Question
STM32F103 UART Tx interrupt
Posted on February 07, 2015 at 13:30
Hell all,
I have two UARTS connected to two devices (say A and B). Both UARTs Tx and Rx is interrupt based. When I receive a message from A (ASCII-Z string) and the same message is sent to B, I am getting the message twice. Here is the example 1. Message sent by A '':03 21'' (NULL terminated). 2. Message received by B '':03 21<0>03 21'' I checked by sending a different message (not the one received from A), say ''Hello'' and this is transmitted properly to B. I am using two receive and two transmit buffers of sufficient length. Message received from A (A's receive buffer) is copied to B's transmit buffer and to trigger transmission, the first character is sent and thereafter the Tx interrupt sends the all the characters till NULL. I can post code snippets if one has time to spare. What could be the problem? Tx interrupt code is pasted below. if (USART_GetITStatus(USART1, USART_IT_TC) == SET ) { if (g8_usrt1_tx_buf[g16v_usrt1_tx_index] != '\0') USART_SendData(USART1,g8_usrt1_tx_buf[g16v_usrt1_tx_index++]); else { USART_ClearITPendingBit (USART1, USART_IT_TC); g8v_usrt1_tx_progress_flag = 0; } } // routine which triggers sending is given below void start_tran_usrt1 (char *mptr) { while (g8v_usrt1_tx_progress_flag == 1); // wait here till flag is reset. Remove this statement later strcpy (g8_usrt1_tx_buf, mptr); g8v_usrt1_tx_progress_falg = 1; g16v_usrt1_tx_index = 1; USART_SendData(USART1,g8_usrt1_tx_buf[0]); // trigger for transmission to start } #stm32-interrupt-serial-transmit