cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4: can only read one byte off the serial

Posted on April 29, 2015 at 02:34

Hi all, 

   I'm having some trouble reading more than one byte off the USART port I've configured. I'm implementing a polling receiver, as follows:

  char *end_obuf = obuf+len;

  char *start_obuf = obuf;

  int delay_count = 0;

  char newData = -1;

  while(obuf < end_obuf) {

    if(SET == USART_GetFlagStatus(ctx->usart, USART_FLAG_RXNE)) {

      newData = USART_ReceiveData(ctx->usart);

      *obuf = (char)newData;

      obuf++;

      delay_count=0;

    } //end if there's data on RX

    else {

      //if there's no NEW data off the RX

      if(MAX_RX_DELAY == delay_count) {

        if(-1 == newData)

          return UARTERR_RX_NODATA;

        else

          break;

      }

        

      SCAN_DelayBusymilliSecs(1); //10ms

      delay_count++;

    } //end if no data on RX

  } //end while there's available space in obuf

When I slap a debugger on this, I get to USART_ReceiveData(<usart handle>) just the one time.  I do notice the SR status register has the value 0xF8 to it (before it magically clears out to 0xC0 a short time later)

So this means, according to these #defines in my STM32 code base:

#define USART_FLAG_TXE                       ((uint16_t)0x0080)

#define USART_FLAG_TC                        ((uint16_t)0x0040)

#define USART_FLAG_RXNE                      ((uint16_t)0x0020)

#define USART_FLAG_IDLE                      ((uint16_t)0x0010)

#define USART_FLAG_ORE                       ((uint16_t)0x0008)

The first 3 flags are expected, but not these last 2.  

How do I deal with these conditions?

I also implemented an interrupt-based receiver, but similar problem.  My Rx is always in an overflow state.

Any thoughts as to what I'm doing wrong?

Thanks, Charles.

1 REPLY 1
Posted on April 29, 2015 at 03:17

What board, pins, USART and baud rate are we talking about.

Does transmit work? Does a simple echo back work?

What if you do the loop without the delay?

Be aware that looking at the registers with a debugger will break the USART functionality, it's not transparent.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..