What should I do if the stm32 serial port is lost?

"STM32 serial port transmission must first detect the status, otherwise the first byte cannot be sent. After the transmission is completed, it must detect whether the transmission status is completed. Otherwise, the transmission is unsuccessful. When using stm32f10x to debug serial communication, an error occurs, and the hardware reset is restarted. After that, the test data is sent 0x01 0x02 0x03 0x04. The data received by the receiver is: 0x02 0x03 0x04, the first data is lost. The data is sent to another value, such as 0x06 0x0ff, then 0x0ff is received, 0x06 is lost. The error remains.


Troubleshooting process: 1, initially suspected to be the receiver error, I use the computer serial port, run the serial port auxiliary debugging tool to receive, after switching to other software, found that the fault remains, and the computer software is always open, unlike computer software related. 2, using single-step debugging, single-step operation of each send command, are normal. Can receive 0x01 0x02 0x03 0x04 data. Indirect exclusion of problems other than computer software, but other errors. 3. Although the single-step debugging operation is normal, the error remains after continuous operation. Now I can't touch the clue. The single step is normal. It seems that there is no error in programming. What is the fault? The test procedure is as follows

USART_SendData(USART2, 0x01); //A while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET); //B USART_SendData(USART2, 0x02); //C while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET); USART_SendData (USART2, 0x03); while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET); USART_SendData(USART2, 0x04); while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);

4. Guess, perhaps because of a special reason, the second data covers the first data, making the first data lost. Assume that when the B instruction is executed, the USART's TC status bit == SET, then the C instruction will be executed immediately, and data coverage may occur. So, before the A command, add the following command: USART_ClearFlag (USART2, USART_FLAG_TC);

5. After adding the previous instruction, run and the error disappears. Explain the previous hypothesis, which should be established.

6. Check the stm32f10x reference manual and find a sentence like this: TC: Send Complete This bit is set by the hardware when the transmission of a frame containing data is completed. If the TCIE in USART_CR1 is 1, an interrupt is generated. This bit is cleared by the software sequence (first read USART_SR and then written to USART_DR). The TC bit can also be cleared by writing a 0, which is recommended only in multi-cache communication.

0: The transmission has not been completed; 1: The transmission is completed.

7. Note this sentence: This bit is cleared by the software sequence (read USART_SR first, then USART_DR). In other words, you must first read USART_SR and then write USART_DR to clear the TC status bit. After the hardware reset, the first data sent by the serial port does not have the read SR operation, and the write DR is directly written, that is, the TC is not cleared. Explain that the guess in step 4 is correct.

8, then, should be added to the USART_ClearFlag (USART2, USART_FLAG_TC); in front of the command A to USART_GetFlagStatus (USART2, USART_FLAG_TC);, should also eliminate the error. After the test, it is confirmed that this is the case. Before sending the first data, read USART_SR first, then the first data loss will not occur.

9. Summary: After the hardware reset, before the serial port sends the first data, first read the USART_SR, then it can ensure that the first data is sent without coverage. Of course, there are other methods, such as clearing the TC status bit first, or adding a small delay after the write USART_DR, so that the data is sent, it should also indirectly eliminate this error.

3 In 1 Usb Cable

Nowadays, the function and appearance of mobile phones are similar, but the charging interface is not unified. The Android camp has Micro USB and Type-C ports, while the iPhone camp has Lightning. Different charging ports use different charging cables, which is very unfriendly for users who often need to use multiple phones. To solve this awkward situation, the three-in-one data cable was born. What is the three-in-one data cable? Three-in-one data cable means that one data cable includes Micro Usb Cable, USB Cable For Iphone and Usb Cable Type C. So one data cable can be used by all mobile phones.

Three-in-one data line is also known as multifunctional data cable. In the original data cable, the combination scheme is added, and the combination PCB is configured, which can support a variety of equipment and avoid the trouble of frequently looking for data line. It combines Lightning, a 30-pin port, and a Micro USB port, and is compatible with multiple devices. It can connect to any smartphone or tablet, including iPhone, iPad, Samsung, etc.

From the technical point of view, the three-in-one data cable does have a strong advantage. With continuous development and improvement, three in one data cable products in the original data cable appearance with woven cloth, will also add a light color on the three in one data cable, so that the data cable function is stronger and more exquisite, more and more people accept and buy. In the era of big data,the 3 In 1 Usb Cable can be said to have deeply affected our work and life. We believe that with the technical development of 3-in-1 mobile phone data cable, it will bring us more convenient transmission experience.





0 1


3 In 1 Usb Cable,3 In 1 Data Cable,3 In 1 Usb C Cable,3 In 1 Universal Cable

Henan Yijiao Trading Co., Ltd , https://www.yjusbhubs.com

Posted on