cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F207 send and receive byte stream using USART

skdeka
Associate II
Posted on June 12, 2012 at 13:21

Hi,

I am new to the STM32 micro-controller. I am using STM32F207 board to communicate with another custom micro-controller board. The communication is basically sending commands and receiving response using USART6 ISR from the custom board. The size of response from the board might very and we need to read complete response data . Can anyone please tell me is there any Hardware FIFO in STM32 USART?

How can I read the complete response data from Interrupt once it hit first time? Also can I use USART_ReceiveData(USART6) in loop inside the ISR?

Is there alternative approach?

regards,

Skdeka

3 REPLIES 3
Posted on June 12, 2012 at 13:32

No, the STM32 does not have a hardware FIFO, rather a single holding register.

You could catch the RXNE interrupt, but this would give you a single character with USART_ReceiveData(), you really wouldn't want to spin waiting for additional characters in the interrupt as you could be there for tens of thousands of cycles depending on the baud rate.

Suggest you use a buffer and accumulate enough data to process.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
skdeka
Associate II
Posted on June 12, 2012 at 14:03

Thanks Clive.

On transmit, can I use a loop to send Byte stream using USART_SendData(USART6, cChar ) inside TX ISR or I can send only one byte at time from the TX ISR?

The following is the code in my receive handler RX ISR

------------------------

if( USART_GetITStatus( COMPORT, USART_IT_RXNE ) == SET )

{

   USART_ITConfig( USART6, USART_IT_RXNE, DISABLE );

   byte = USART_ReceiveData( USART6 );

   buff[count++]= byte;

   if(count < MAXBUF)

       USART_ITConfig( USART6, USART_IT_RXNE, ENABLE );

}

-------------------------------

If there anything wrong in that piece of code? Is the call to USART_ReceiveData() clear RXNE?

      

  

Posted on June 12, 2012 at 15:54

You really don't want to be dwelling in the interrupt service routine, put the data in a buffer, service one at a time. If you want to background the operation use DMA to send long bursts of data and catch the TC interrupt on the DMA channel/stream.

RXNE is cleared by reading the data register. No need to disable/enable the RX interrupt. For TX be aware that if you don't have and data to post and clear the interrupt it will keep reentering the service routine, disable the TXE interrupt when you have no data pending.

if( USART_GetITStatus( USART6, USART_IT_RXNE ) == SET )

{ byte = USART_ReceiveData( USART6 ); // Clears the interrupt source if(count >= MAXBUF) USART_ITConfig( USART6, USART_IT_RXNE, DISABLE ); else { buff[count++]= byte; if(count >= MAXBUF) USART_ITConfig( USART6, USART_IT_RXNE, DISABLE ); } } You should probably also address error conditions like overruns, framing or parity, as appropriate.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..