cancel
Showing results for 
Search instead for 
Did you mean: 

Usart 2 interrupt problem STM32F303CC

m_
Associate II
Posted on December 08, 2014 at 16:06

Hello

I'm using a STM32F303CC lqfp 48 on a new product. I'm trying to use 3 Usart channels. I succesfully use channel 1 and 3 but channel 2 is acting weird. In configure the three channels all in the same manner. But channel 2 keeps firing interrupts. Below is my code for the initialisation and the interrupt routine:

void Usart2_Init(void)
{
//GPIO Init
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, 7);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, 7);
// USART init
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
//Interrupts for uart 2
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; // we want to configure the USART1 interrupts
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;// this sets the priority group of the USART2 interrupts
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // this sets the subpriority inside the group
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // the USART1 interrupts are globally enabled
NVIC_Init(&NVIC_InitStructure); // the properties are passed to the NVIC_Init function which takes care of the low level stuff
USART_ClearFlag(USART2, USART_IT_RXNE);
USART_ClearFlag(USART2, USART_IT_TXE);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
// Ringbuffers for transmit and receive
RingBufferInit(&uart2RXRingBuffer);
RingBufferInit(&uart2TXRingBuffer);
}

And this is my interrupt routine:

void USART2_IRQHandler(void)
{
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) // Characters received
{
USART_ClearFlag(USART2, USART_IT_RXNE);
RingBufferPutChar(&uart2RXRingBuffer, USART_ReceiveData(USART2));
}
else
{
USART_ClearFlag(USART2, USART_IT_TXE);
if (!RingBufferEmpty(&uart2TXRingBuffer)){
USART_SendData(USART2, RingBufferGetChar(&uart2TXRingBuffer));
}
else
{
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
}
}
}

I would really appreciate help because I'm really stuck. My sincerly. #stm32f303 #usart #interrupt
10 REPLIES 10
thaian1112006
Associate II
Posted on July 19, 2016 at 11:54

I solve problem with RXNE IT, just connect RX pin to Vcc with 10K resistor. TXE still have same problem. Thanks clive1, you help me alot.

Kind regards.