AnsweredAssumed Answered

STM32F100RB UART Interrupt Problem

Question asked by schweizer.tobias on Sep 21, 2012
Latest reply on Sep 21, 2012 by Clive One


I'm currently trying to implement a UART driver with interrupt handling for the STM32F100RB on my Discovery board.
Therefore, the function UART_Init() configures the UART1 and enables the interrupts TC and RXNE. Exactly at this point, the interrupt service routine is executed one time. When I'm debuggin the software, I see that the bit USART_SR_TC in the uart status register is set. But it is not cleared by reading the status register (as it is described in the datasheet of the controller).
For test purposes, I'm writing a data byte to the uart data register. Then, the interrupt service routine is executed all the time. Do I have to reset another interrupt flag (maybe in the NVIC?)?

Does anybody have a working uart code with interrupt usage?

Here's my code (the uart irq is enabled in the NVIC register, of course).

void UART_Init(void)
  /* enable clock for UART */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

  USART1->BRR = (24000000 / 115200);

  /* init ringbuffer */
  ringbuffer_init(&uart_tx_ringbuffer_s, uart_tx_data_ac, UART_TX_BUFFER_LENGTH);

  uart_status_ec = UART_STATE_IDLE;

  USART1->DR = 0xAA;

void USART1_IRQHandler(void)
  if ((USART1->SR & USART_SR_TC) != 0x00)
    /* Transmission clompete interrupt */
    uart_status_ec = UART_STATE_IDLE;