STM32L051 UART Frame error
Hi,
i have some troubles with UART receive, unfortunately I had no explanation. I am new with STM32 MCU. Here is the issue:
- The communication was working fine after power on, until the MCU access the EEPROM or when I tried to pause in debug mode. After that's, the framing error status is set permanently. Reset the MCU then it works again.
Here are my initial uart and received ISR code
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Enable clock */
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/* Init TX, RX Pins alternate function */
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = IOL_RX_GPIO_AF;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = IOL_TX_GPIO_AF;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
uint32_t tmpreg = 0;
tmpreg = USART_CR1_M0 | USART_CR1_PCE | USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE;
USART1->CR1 = tmpreg;
uint16_t usartdiv = (uint16_t)(SystemCoreClock/230400);
USART1->BRR = usartdiv;
USART1->CR3 |= USART_CR3_OVRDIS | USART_CR3_ONEBIT;
uint32_t status = USART1->ISR;
USART1->ICR = status;
status = USART1->RDR;
USART1->CR1 |= USART_CR1_UE;
/* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);void USART1_IRQHandler(void)
{
uint32_t status = 0;
uint8_t ui8_usart_data = 0;
if(USART1->ISR & USART_ISR_RXNE)
{
/* Framing error and parity error */
status = USART1->ISR & 0xF;
ui8_usart_data = USART1->RDR;
if(status)
{
USART1->ICR = status;
}
CallbackReceivedInterrupt(ui8_usart_data, (uint8_t)status);
}
}Can someone pls explain me this issue or maybe i forgot a uart settings?
I already read some threads. Someone say that the ISR callback function should not be long. I think my callback funtion is not long, cause it always work after power on. I only ported the software to this new MCU STM32L051. The software works fine with other MCUs (in 4 different MCUs) and I did not see this issue in other MCU. I also did not access the EEPROM inside the callback function.
I appreciate for any ideas and thanks in advance!
Best regards
