2015-04-28 05:34 PM
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 obufWhen 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.2015-04-28 06:17 PM
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.