I'm trying to send data from C# app to the one STM32 dev board via USB CDC. I have problem with method SerialPort.Write() because write method send only first character instead of all characters of array or string. Same situation is it with serial terminals (terminte, cutecome,..) when attempt to send string. Can someone explain me how cdc usb really works. Does STM32 send data in same manner, character by character in each frame? I didn't use logic analyzer to see signals but that will be next step maybe.
If anyone has picture of usb cdc frame please share.
When I send string from STM32 dev board to the C# app that works fine. Any idea is welcome
The C# SerialPort.Write function is capable of writing an entire string at once if you call it the right way. The bytes of the string will be passed on to your operating system's USB drivers, which will split it up into packets according to the max packet size for the endpoint specified in your device's USB descriptors. Then those packets will be sent to the device, one packet at a time.
I suspect that there is a bug in your STM32 code, but since you have not posted an MCVE it will be difficult to help you debug any code.
Related
I have a project using MDB (multi-drop bus) for vending machine (VDM).
The VDM has a MDB-RS232.
I'm not sure if it converts 9bit - 8bit (MDB-UART).
How do I read data from VDM in my computer?
Thanks all
MDB (multi-drop bus) is 9 bit, because after the standard 8 data bits (like in standard RS232 UART communication) there is a 9th bit called "mode".
(Wikipedia on MDB: "the mode bit differentiates between ADDRESS and DATA bytes.")
But you can read such data even with regular 8-bit RS232 interfaces, e.g. a plain standard USB-to-RS232 device for PC.
Here is how:
Use 9600 baud, 8 data bits, 1 stop bit, but RS232 parity setting "Space". Make sure you receive the original character value even in case of a Parity Error indication. Any MDB address byte from your VDM will be received with a Parity Error (but still be displayed correctly). Any data byte will be displayed without error.
For sending MDB ADDRESS and DATA bytes using a standard 8-bit RS232 port, you could apply temporary parity changes: Change the parity setting to "Mark" before sending an address byte, then change back to "Space" before sending data bytes.
On Windows, you can do such tricks with our Docklight software (see Docklight and MDB). It's free for basic testing and there is also a related 9-bit example project.
On Linux / Raspberry Pi other users have successfully implemented the parity trick, too, see this stackexchange post about a MDB + Pi.
But also with RealTerm, Teraterm, Termite, Bray, YAT or any other RS232 application you should be able to read the data, as long as it handles "Space" or "Mark" parity settings correctly.
You'll need an adapter which will do all convert operations on-the-fly and in real time. If you want to emulate VMC (master), you'll need MDB-UART master adapter. If you want to emulate MDB peripheral device (such as coin changer, bill validator etc), you'll need this. For two-way "sniffing" MDB bus you'll need a combination of these devices.
Direct connection PC's RS-232 to MDB will not work due to strict MDB timings (delay between VMC command and peripheral response must not exceed 5ms, delays between POLL requests are 50-300ms in general). I mean pretty reliable functioning available for commercial purposes.
I have been trying to set up two XBees to communicate since the last three days. X-CTU seems to be the perfect option to do so, however, it is a real menace when it comes to discovering XBees on serial ports.
I was able to detect one XBee by luck just once and the other one never showed up. I have even replaced both my XBees. I am trying to figure out the alternative, i.e. using a serial console to perform the operation. I haven't been able to receive an OK response from the device upon issuing +++.
Since I haven't had a good experience using a PC to communicate with ESP8266 devices earlier, I tried to figure out a workaround by using the second Serial port of an Arduino to send such configuration messages and read the response by printing it out on the default serial console.
It also appears that configuration messages can differ depending on the mode of the device. If it's in API mode, the frame has to be generated in a specific format (I use the X-CTU frame generator for this purpose).
Why am I not able to receive a response from the XBee upon issuing a +++?
The devices are Series 1 XBees and the exact part number is XB24-AWI-001. Any help is highly appreciated.
Have you considered the XBee being in API mode? Maybe should you consider to reflash the device in AT mode to start playing with it.
To test if it's in API mode, you can refer to the guide, chapter 9 for the API mode structure:
http://eewiki.net/download/attachments/24313921/XBee_ZB_User_Guide.pdf?version=1&modificationDate=1380318639117&api=v2
Basically, a datagram in API mode starts with ~, and it's built as follows:
[0x7E|length(2B)|Command(1B)|Payload(length-1B)|Checksum(1B)]
As 0x7E is ~ on the ASCII table, you should try typing a bogus datagram in a serial terminal session like:
~ <C-d> AAAA
N.B.: The <C-d> characters means Control-d under unix., which is the EOF character.
Obviously such a message isn't likely to work, and you will receive a reply asking you to send that datagram again. That's because the EOF character being ASCII code 4, it means that the length of the datagram will be 4 bytes. So then you send four bogus bytes, the checksum will be A, which is very likely to be right, and the receiver will assume the transmission has been corrupted. So the datagram will be asked again, meaning you will receive a datagram to do that query.
Though I can only advice you to consider running it only in API mode (more reliable and a better API, but you cannot play around with it and understand what's going on by tapping on the line with a logic analyzer… though giving enough time, you'll start to read API datagrams like it's English ☺).
I wrote a page with a few resources to check on how to reflash the XBees:
https://github.com/hackable-devices/polluxnzcity/wiki/Flash-zigbee
and here's other advices from another totally unrelated project:
https://github.com/andrewrapp/xbee-api#documentation
And I also wrote a lib (aimed at beaglebones but you can tweak it for your use) that handles API mode 2 with XBees:
https://github.com/hackable-devices/polluxnzcity/blob/master/PolluxGateway/include/xbee/xbee_communicator.h
https://github.com/guyzmo/polluxnzcity/blob/master/PolluxGateway/src/xbee/xbee_communicator.C
but I bet with a little google search you can find more widely used libraries than those ones, and even some aimed to be run on Arduinos (N.B.: that lib was originally written for Arduinos, and then adapted to run for Beaglebone, so reversing the operation shouldn't be hard).
Hello I am trying to get my ESP to run a webserver that will accept a string of text an output that text through a the uart serial pins to my arduino I can't find out how to do it I would apreshiate it
My seyup would be
Arduino connected to the esp through serial pins the esp would start a server and my pc would open the webserver and type in a string of text that string would transmit to the arduino
I can't comment yet, so I'll put this in an answer :)
What I understand is you want a simple 'webserver' on your ESP, that listens to simple GET requests, takes the query string, and sends that over the serial line to your Arduino.
Firstly, are you capable of flashing new firmware to the ESP?
It's not hard, but as I understand your request, you will need to be able to do it.
Then you need to pick what would be your preferred approach:
Flash NodeMcu firmware, and expand the webserver lua example to do what you want.
Set up the Arduino IDE to work with the ESP (tutorials exist), and write a Arduino sketch to do what you want.
You could also use esp-open-sdk, or the official Espressif SDK, and write what you want in C, but since you sound like a beginner, the two previous options are likley a better choice, their easier.
I expect the NodeMcu/lua way might be the quickest, although if you're already familiar with the Arduino IDE that might be a better choice.
If there are details you are stuck on, expand your question, and I'll see if I can stick them in the answer.
I am trying to connect a joystick to my pc. The device has a serial cable which is supposed to be inserted into another device (a steering wheel), but instead I want to use it directly. Eventually I plan to connect it to a program that am currently writing.
How can I communicate with this device? I know how to communicate to a serial device, I just don't understand what I should send and expect to receive.
Debugging attempts:
If I connect it directly to my PC's serial device and using a program such as moserial I can sort of communicate with it, if I pound on the keyboard it returns (usually) one byte and "=\n" per byte sent. The return codes do not seem to always correspond to the state of the joysitck. It seems to be returning the same value for the same value. Once or twice I noticed that if I send a large amount of random data I can get it to hang until I switch the position of the joystick. But for the most part there seems to be nonsensical responses (same input per output regardless of state). I also tried a serial-to-usb converter which had a different result. Under USB the device does pretty much nothing regardless of the baud rate. I have noticed that if I send an incredible amount of random kepresses I occasionally get a single unprintable character in response.
I was expecting to get a continuous stream of numbers corresponding to the state of the joystick.
Summary:
I don't know if my direct serial connection is just showing noise, I did try a second serial to USB converter which had the same results. Any ideas or suggesting in determining how to communicate with this device?
I need to send data (an integer) from an Arduino to a C program on a PC. I know that the connection is fine, because with X-CTU works perfectly. I need to do this in AT mode but I don't know how to start.
If you're using the XBee modules in AT mode, then it isn't much different than what you'd have to do with a direct serial cable connection between the Arduino and PC. Look for sample programs demonstrating serial communications for both platforms.
Having the connection working with X-CTU is an excellent starting point, since you have confirmed that the radio modules are communicating correctly.
On the PC, you might want to look at this Open Source XBee Host Library on GitHub. It includes a sample program called "xbee_term" that demonstrates a simple serial terminal for using an XBee in AT mode. It also has a layered API to allow for easy use of XBee modules in API mode -- which you would need to use if the PC was going to communicate with multiple Arduino nodes running in AT mode.
As for sending an int, you can use sprintf() to format it as a string to send over the wireless link, and strtol() to convert it back to an int on the PC end.