The solution is to immediately read a byte as soon as it arrives in serial port buffer and store it in data array before doing anything else. In the second case you send one byte (0x01), it is stored in the serial port buffer, you read it and store it in data before you send the next one (0x02), your code waits 5 secs before reading that second value and storing it, it then immediately attempts to read the third byte (no wait (5) in between) and fails because you either have not yet pressed the send button again and the serial port is still empty or the third byte was lost because the serial port buffer was still occupied with 0x02 when 0x03 arrived. So when you send three bytes in one burst the first one will be stored in the serial port buffer and you read it OK, then you wait 5 sec and try to read the next two, but they have not been saved because the serial buffer was still filled with 0x01 when they arrived. If you want to use your computer to communicate with external devices, you can use CoolTerm to make this procedure fast and easy.The STM32F767 probably doesnt have a hardware fifo (check datasheet) so you need to read the received byte from the serial port before the next one arrives or that next byte will be lost. CoolTerm is free and it doesn't need to be installed. The application allows you to send ASCII or Hex strings, save received data in plain text files or send text files. You can establish a connection with one or more external devices almost instantly. Other options, located in the Connection menu, allow you to send brakes, reset or flush serial ports. If you turn on this feature and specify an output path, the received data will be saved in plain text file, without any user intervention.ĪSCII and Hex strings can be typed and issued on a separate window. The application is also capable of sending data to a text file automatically. Received data is displayed as plain text, in the central region of the interface, but you can display it in hexadecimal format as well. You may launch separate CoolTerm instances and connect to different ports. The software supports multiple concurrent connections. Ports can be selected in the general settings panel, where you can make other adjustments as well, like selecting different values for baudrate, data bits and stop bits, parity and others. If you have one or more serial ports available, you can establish a connection right away, by clicking the appropriate option, on CoolTerm's interface. Besides that, it is worth mentioning that CoolTerm is distributed as a freeware application. Its files can be extracted directly from a ZIP archive, so you don't have to go through an installation process. The application is designed for Windows, but you can use it on Mac OS X and Linux as well. You can use this application as a terminal, to issue commands to servo controllers, robotic kits, GPS receivers and many other devices. CoolTerm allows you to exchange data with devices that are connected to your computer via serial ports. Windows makes it easy to execute all sorts of actions on a computer, but it does not help you with much, when it comes to controlling external hardware.
0 Comments
Leave a Reply. |