2019-08-14 06:56 AM
Hi !
I am writing a code that uses the UART1 and I would like to work on RX interrupt to handle incoming strings.
To start with it, I wrote a code that simply initialise the UART and send a character once the RX Interrupt is fired:
#ifndef HSE_VALUE
#define HSE_VALUE 8000000UL
#endif
#ifndef HSI_VALUE
#define HSI_VALUE 16000000UL
#endif
#include "stm32f4xx.h"
#include "stm32f4xx_ll_bus.h"
#include "stm32f4xx_ll_rcc.h"
#include "stm32f4xx_ll_usart.h"
#include "stm32f4xx_ll_gpio.h"
#include "stm32f4xx_ll_system.h"
#include "stm32f4xx_ll_pwr.h"
void USART1_IRQHandler(void)
{
if(LL_USART_IsActiveFlag_RXNE(USART1))
LL_USART_ClearFlag_RXNE(USART1);
if(LL_USART_IsActiveFlag_IDLE(USART1))
LL_USART_ClearFlag_IDLE(USART1);
LL_USART_TransmitData8(USART1, '!');
}
int main(void)
{
// GPIO AF config
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_9 | LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_9 | LL_GPIO_PIN_10, LL_GPIO_SPEED_FREQ_VERY_HIGH);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_9, LL_GPIO_AF_7);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_10, LL_GPIO_AF_7);
// NVIC config
NVIC_SetPriority(USART1_IRQn, 0x0);
NVIC_EnableIRQ(USART1_IRQn);
// UART config
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
LL_USART_Disable(USART1);
const uint32_t pclk = __LL_RCC_CALC_PCLK2_FREQ(SystemCoreClock, LL_RCC_GetAPB2Prescaler());
LL_USART_SetBaudRate(USART1, pclk, LL_USART_OVERSAMPLING_16, 115200);
LL_USART_SetDataWidth(USART1, LL_USART_DATAWIDTH_8B);
LL_USART_SetStopBitsLength(USART1, LL_USART_STOPBITS_1);
LL_USART_SetParity(USART1, LL_USART_PARITY_NONE);
LL_USART_SetTransferDirection(USART1, LL_USART_DIRECTION_TX_RX);
LL_USART_SetHWFlowCtrl(USART1, LL_USART_HWCONTROL_NONE);
LL_USART_SetOverSampling(USART1, LL_USART_OVERSAMPLING_16);
LL_USART_DisableSCLKOutput(USART1);
LL_USART_Enable(USARTx);
LL_USART_EnableIT_RXNE(USART1);
while(1)
{
//LL_USART_TransmitData8(USART1, 'x');
;
}
}
The code for the UART initialization seems correct because I can send the '*' character in the infinite loop, but I can't send nothing from the USART1_IRQHandler ISR...
What am I missing for the interrupt initialization ?
Thanks.
s.