2017-03-05 10:53 AM
Hi,
I'm working on STM32F091 MCU fora the first time and I'm trying to test the USART1 on PF0,1. I have just wrote the code and it works well, but now I can't receive the RXNE interrupt.. the tx line works normally.. if I try to set the port as an input I see the correct logic level on pin so the port works, it seems that the shift register of USART NOT WORK. Any idea?
Thanks.
lorenzo.
2017-03-05 11:35 AM
>>Any idea?
Show the code, and indicate what model of STM32F091 specifically you are using, and that has USART1 on PF0 and PF1
Both TX, and RX pins should be configured in AF mode, and muxed correctly.
2017-03-06 04:57 AM
Hello !
did you actually use the STMCube firmware, did you you STMCubeMX to configure your pins ?
did you check that the IRQ is enabled ?
It's actually hard to give an answer without any code information ?
2017-03-07 12:34 PM
Thanks for the reply!
The code is very simple just configure the pin and the speed like ST example, the code works. I've connected the STM with the Max232 but is supplied with 5V.. it maybe the problem?
2017-03-07 02:16 PM
A MAX3232 would be more appropriate. I suspect most pins are 5V tolerant at this point, but check the Data Sheet.
What part / board are you using. Give all the digits of the part number so I can at least correlate your PF0 and PF1 pining to some part supporting the USART there.
>>
The code is very simple just configure the pin and the speed like ST example, the code works.
Let me judge the validity of the code, cause you're complaining it is not working, so something is wrong with your logic at some level.
2017-03-08 01:21 AM
I'm using the STM32F091RBT6 on my board, and the USART1 port are PA9&PA10.
This is the code:
void UsartInit (void) {
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // enable clock for Alternate Function
GPIOA->MODER |= 0x280000;
GPIOA->AFR[1] |= 0x110;
GPIOA->OSPEEDR |= 0x300000; //PA10
USART1->BRR = 0x1388; // set baudrate 9600BAUD
USART1->CR1 |= (USART_CR1_RE | USART_CR1_TE);
NVIC_EnableIRQ(USART1_IRQn);
USART1->CR1 |= USART_CR1_UE; // USART enable
USART1->CR1 |= USART_CR1_RXNEIE;
}
The TX line works and also the RX line has worked but now it van't receive the RXNEIE interrupt.. if I enable the IDLE line interrupt I receive the interrupt so the interrupt configuration works.
Thanks.
Lorenzo.
2017-03-08 01:59 AM
Don't you observe the USART in a debugger while running? That would clear the RXNEIE flag through the software sequence, preventing the interrupt to happen.
JW
2017-03-08 05:35 AM
Hi
Meneghello.Lorenzo
,Just additional ideas of checks :
1) Could you try to pull up GPIOA->PUPDR9 and 10 ?
2) In case some data has already been received on Rx line, prior you enable RXNEIE, it could be that ORE (overrun flag) is already set. This error prevents from further RXNE interupts to be raised (allowing to retrieve and not overwrite already received data). Could you check status of ORE flag in USART1->ISR ?
If set, could you try adding a clear of ORECF flag in USART1->ICR prior starting reception ?
Guenael
2017-03-08 08:21 AM
Yes I had already added the code to clear the ORE flag.. I've tried also the pull-up, I think that does not support 5V and the internal circuitry not work for me.
2017-03-08 08:30 AM
It is more probable that it simply isn't receiving data in the expected format
USART1->BRR = 0x1388; // set baudrate 9600BAUD
And what exactly is the APB clocking at ?
At 24 MHz, 9600 baud would be BRR = 0x9C