2018-04-10 05:27 AM
Hello,
I am having a problem with RX interrupt. Everytime I callLL_USART_TransmitData8() it triggers RXNE flag. I enabled only RXNE , ERROR and disabled TXE. Also, If I send bytes to UART does not trigger RXNE interrupt.
I am running the firmware with freeRTOS, so maybe is a priority problem? UART priority is 6 = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORIT(5) + 1.
void Configure_Modem_USART(void)
{
/* Enable the peripheral clock of GPIO Port */
MODEM_USARTx_GPIO_CLK_ENABLE();
/* Configure Tx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_MODE_ALTERNATE);
MODEM_USARTx_SET_TX_GPIO_AF();
LL_GPIO_SetPinSpeed(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(MODEM_USARTx_TX_GPIO_PORT, MODEM_USARTx_TX_PIN, LL_GPIO_PULL_UP);
/* Configure Rx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_MODE_ALTERNATE);
MODEM_USARTx_SET_RX_GPIO_AF();
LL_GPIO_SetPinSpeed(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(MODEM_USARTx_RX_GPIO_PORT, MODEM_USARTx_RX_PIN, LL_GPIO_PULL_UP);
/* (2) NVIC Configuration for USART interrupts */
/* - Set priority for USARTx_IRQn */
/* - Enable USARTx_IRQn */
NVIC_SetPriority(MODEM_USARTx_IRQn,
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY+1);
NVIC_EnableIRQ(MODEM_USARTx_IRQn);
/* (2) Enable USART peripheral clock and clock source ***********************/
MODEM_USARTx_CLK_ENABLE();
/* Set clock source */
MODEM_USARTx_CLK_SOURCE();
/* (3) Configure USART functional parameters ********************************/
// HAL configuration
USART_ModemHandle.Instance = MODEM_USARTx_INSTANCE;
USART_ModemHandle.Init.BaudRate = 115200;
USART_ModemHandle.Init.WordLength = USART_WORDLENGTH_8B;
USART_ModemHandle.Init.StopBits = USART_STOPBITS_1;
USART_ModemHandle.Init.Parity = USART_PARITY_NONE;
USART_ModemHandle.Init.Mode = UART_MODE_TX_RX;
//USART_ModemHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
USART_ModemHandle.Init.CLKPolarity = USART_POLARITY_HIGH;
USART_ModemHandle.Init.CLKPhase = USART_PHASE_1EDGE;
USART_ModemHandle.Init.CLKLastBit = USART_LASTBIT_ENABLE;
if (HAL_USART_Init(&USART_ModemHandle) != HAL_OK) {}
/* Enable RXNE and Error interrupts, disable TX */
LL_USART_EnableIT_RXNE(MODEM_USARTx_INSTANCE);
LL_USART_EnableIT_ERROR(MODEM_USARTx_INSTANCE);
LL_USART_DisableIT_TXE(MODEM_USARTx_INSTANCE);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Interrupt handler
void MODEM_USARTx_IRQHandler(void)
{
__IO uint32_t received_char;
if (MODEM_USARTx_INSTANCE->ISR & USART_ISR_ORE) // Overrun Error
MODEM_USARTx_INSTANCE->ICR = USART_ICR_ORECF;
if (MODEM_USARTx_INSTANCE->ISR & USART_ISR_NE) // Noise Error
MODEM_USARTx_INSTANCE->ICR = USART_ICR_NCF;
if (MODEM_USARTx_INSTANCE->ISR & USART_ISR_FE) // Framing Error
MODEM_USARTx_INSTANCE->ICR = USART_ICR_FECF;
/* Check RXNE flag value in ISR register */
if(LL_USART_IsActiveFlag_RXNE(MODEM_USARTx_INSTANCE) &&
LL_USART_IsEnabledIT_RXNE(MODEM_USARTx_INSTANCE))
{
/* RXNE flag will be cleared by reading of RDR register (done in call) */
if (idx_rx < BUF_SIZE) {
received_char =
LL_USART_ReceiveData8(MODEM_USARTx_INSTANCE);
recv_buff[idx_rx++] = received_char;
}
else
idx_rx = 0;
}
else
{
/* Call Error function */
//Error_Callback();
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
#freertos #stm32l4-hal #uart-rx-interrupt-routine
Solved! Go to Solution.
2018-04-10 11:24 AM
Hi,
Problem solved.For some reasonHAL_USART_Init() does not work for transmit and receive with RX interrupt enabled. I am usingLL_USART_Init() instead and works very well.
LL_USART_InitTypeDef usart_initstruct;
usart_initstruct.BaudRate = 115200;
usart_initstruct.DataWidth = LL_USART_DATAWIDTH_8B;
usart_initstruct.StopBits = LL_USART_STOPBITS_1;
usart_initstruct.Parity = LL_USART_PARITY_NONE;
usart_initstruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
usart_initstruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
usart_initstruct.OverSampling = LL_USART_OVERSAMPLING_16;
/* Initialize USART instance according to parameters defined in initialization structure */
LL_USART_Init(MODEM_USARTx_INSTANCE, &usart_initstruct);
/* (5) Enable USART *********************************************************/
LL_USART_Enable(MODEM_USARTx_INSTANCE);
/* Polling USART initialisation */
while((!(LL_USART_IsActiveFlag_TEACK(MODEM_USARTx_INSTANCE))) || (!(LL_USART_IsActiveFlag_REACK(MODEM_USARTx_INSTANCE))))
{
}
/* Enable RXNE and Error interrupts, disable TX */
LL_USART_EnableIT_RXNE(MODEM_USARTx_INSTANCE);
LL_USART_EnableIT_ERROR(MODEM_USARTx_INSTANCE);
LL_USART_DisableIT_TXE(MODEM_USARTx_INSTANCE);�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
2018-04-10 06:26 AM
If you are talking to a modem you likely have ECHO turned on, use ATE0 to turn that OFF
2018-04-10 11:24 AM
Hi,
Problem solved.For some reasonHAL_USART_Init() does not work for transmit and receive with RX interrupt enabled. I am usingLL_USART_Init() instead and works very well.
LL_USART_InitTypeDef usart_initstruct;
usart_initstruct.BaudRate = 115200;
usart_initstruct.DataWidth = LL_USART_DATAWIDTH_8B;
usart_initstruct.StopBits = LL_USART_STOPBITS_1;
usart_initstruct.Parity = LL_USART_PARITY_NONE;
usart_initstruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
usart_initstruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
usart_initstruct.OverSampling = LL_USART_OVERSAMPLING_16;
/* Initialize USART instance according to parameters defined in initialization structure */
LL_USART_Init(MODEM_USARTx_INSTANCE, &usart_initstruct);
/* (5) Enable USART *********************************************************/
LL_USART_Enable(MODEM_USARTx_INSTANCE);
/* Polling USART initialisation */
while((!(LL_USART_IsActiveFlag_TEACK(MODEM_USARTx_INSTANCE))) || (!(LL_USART_IsActiveFlag_REACK(MODEM_USARTx_INSTANCE))))
{
}
/* Enable RXNE and Error interrupts, disable TX */
LL_USART_EnableIT_RXNE(MODEM_USARTx_INSTANCE);
LL_USART_EnableIT_ERROR(MODEM_USARTx_INSTANCE);
LL_USART_DisableIT_TXE(MODEM_USARTx_INSTANCE);�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?