AnsweredAssumed Answered

STM32F4: can only read one byte off the serial

Question asked by martin.charles on Apr 29, 2015
Latest reply on Apr 29, 2015 by Clive One
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;

    } //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;
      SCAN_DelayBusymilliSecs(1); //10ms
    } //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.