cancel
Showing results for 
Search instead for 
Did you mean: 

Problem on USART

lorenzo meneghello
Associate II
Posted on March 05, 2017 at 19:53

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.

20 REPLIES 20
Posted on March 05, 2017 at 20:35

>>Any idea?

Show the code, and indicate what model of STM32F091 specifically you are using, and that has USART1 on PF0 and PF1

http://www.st.com/content/ccc/resource/technical/document/datasheet/95/3c/2e/5b/21/09/45/a6/DM00115237.pdf/files/DM00115237.pdf/jcr:content/translations/en.DM00115237.pdf

 

Both TX, and RX pins should be configured in AF mode, and muxed correctly.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Selso LIBERADO
Associate III
Posted on March 06, 2017 at 13:57

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 ?

lorenzo meneghello
Associate II
Posted on March 07, 2017 at 21:34

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? 

Posted on March 07, 2017 at 22:16

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 08, 2017 at 09:21

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.

Posted on March 08, 2017 at 09:59

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

Posted on March 08, 2017 at 13:35

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

Posted on March 08, 2017 at 16:21

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.

Posted on March 08, 2017 at 16:30

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

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..