Forum: Mikrocontroller und Digitale Elektronik STM32 UART Overrun


von Michael W. (Gast)


Lesenswert?

Hallo !

Ich laufe manchmal in einen Receive Overrun, und der UART ist blockiert.

Meine funktionierende Handlerroutine sieht so aus (i ist 0...5 für 
UART1...UART6):
1
void USART_Handler(uint8_t i){
2
3
  if (i >= NUM_UART)
4
    return;
5
6
  if (USART_GetITStatus(UART_Handle[i].USARTp, USART_IT_TXE) == SET){
7
    USART_BufferTx(i);
8
  }
9
10
  if (USART_GetITStatus(UART_Handle[i].USARTp, USART_IT_RXNE) == SET){
11
    USART_BufferRx(i);
12
  }
13
14
}
15
16
...
17
...
18
19
static void USART_BufferRx(uint8_t i){
20
  volatile t_UART_Handle * handle ;
21
22
  char c;
23
  if (i >= NUM_UART)
24
    return;
25
26
  handle = & UART_Handle[i];
27
28
  c = USART_ReceiveData(UART_Handle[i].USARTp); // read data from USART
29
  writeToRing(& handle->receiveRing, c);
30
}

Im Reference Manual steht:
1
...
2
It (ORE) is cleared by a software sequence (an read to the
3
USART_SR register followed by a read to the USART_DR register).

USART_GetITStatus liest doch das SR, und USART_BufferRx liest das DR.
Wieso steht ORE dann trotzdem an? Zählt das hintereinander ausführen 
nicht als "software sequence" ?

Danke, Michael

von Michael W. (Gast)


Lesenswert?

so geht es, scheinbar müssen die beiden Lesebefehle unmittelbar 
hintereinander ausgeführt werden? Vielleicht kann mir das jemand 
erklären...?

Danke!
1
void USART_Handler(uint8_t i){
2
3
  volatile uint8_t dummy = 0;
4
5
6
  if (i >= NUM_UART)
7
    return;
8
9
  if (USART_GetITStatus(UART_Handle[i].USARTp, USART_IT_TXE) == SET){
10
    USART_BufferTx(i);
11
  }
12
  if (USART_GetITStatus(UART_Handle[i].USARTp, USART_IT_RXNE) == SET){
13
    USART_BufferRx(i);
14
    dummy = 1;
15
  }
16
17
  if (USART_GetITStatus(UART_Handle[i].USARTp, USART_IT_ORE_RX) == SET){
18
    if (dummy){
19
      dummy =  UART_Handle[i].USARTp->SR;
20
      dummy = UART_Handle[i].USARTp->DR;
21
    }
22
  }
23
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.