Hi,
I'm using the MCBSTM32E development board equiped with an STM32F103ZE microcontroller.
I configured the USART2 transmitter according the Reference Manual and it works fine.
I configured the USART2 receiver according the Reference Manual and it does not work.
3 hours of experimenting does not do the job. I did next steps: - set the CR1_UE Usart Enable bit - clr the CR1_M bit for selecting 8 data bits - set the CR2 register to 1 stopbit - set the BRR register to the desired bautrate - set the CR1_RE bit to enable the receiver - set the USART RX input pin PA3 to input float - enabled the GPIOA port pheripheral clock - enabled the USART2 peripheral clock - set the CR1_RXNEIE bit to activate receive interrupt - set the NVIC-ISER bit for USART2 (global interrupt) - write an interrupt handler
When I apply data to the RX-input nothing happens. I monitored the receive data (DR) register and status (SR) register but nothing changed. I scoped pin PA3 on the uC and it is toggling when receiving data.
When I force a receive interrupt by setting the USART2 bit in the ISPR register then the interrupt handler is executed.
I changed code to control USART1 but with same effect.
I must have forgotten some bit or made some configuration errer. It seems as if rx-data is not entering the internal shiftregister or is not sampled.
All hints and tips are welcome.
Thanks,
Henk
Have you turned it on (power to CPU)?
>did you set the clock? Yes: - enabled the USART2 peripheral clock
>What about the respective bit in PCONP (power to peripheral) ? There is no such thing like PCONP with the STM32F103ZE microcontroller
>Have you turned it on (power to CPU)? What dou you mean?
I found out that the 'Alternate Function IO Clock' was not enabled. But after enabling it still the receiver does not work.
Did you set the RCC clock FIRST?
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
Yes I think so:
Below is the comment from my source code as it is execute: (I rewrote my UASRT2 code to UASRT1)
//enable the GPIO clock for port GPIOA //enable the GPIO clock for port GPIOB //set the AHB prescaler divisor to 1 (so input frequency = 8.000.000 / 1 = 8.000.000Hz) //set the ABP1 prescaler for timers divisor to 8 (so input frequency = 8.000.000 / 8 = 1.000.000Hz) //set the ABP2 prescaler for timers divisor to 8 (so input frequency = 8.000.000 / 8 = 1.000.000Hz) //reset usart1 //unreset usart1 //enable the USART1 peripheral clock //alternate function io enable //PA09 is Alternate Output Push Pull + PA10 input float // 1. Enable the USART by writing the UE bit in USART_CR1 register to 1. // 2. Program the M bit in USART_CR1 to define the word length.(bit is 0 => 8bits) // 3. Program the number of stop bits in USART_CR2. (both bits are 0 => 1 stopbit) // 5. Select the desired baud rate using the baud rate register USART_BRR (115200 baud) // 6. Set the RE bit USART_CR1. This enables the receiver which begins searching for a // start bit. //enable receive-data interrupt //enable USART1 global interrupt
1. Enable the USART clock (RCC) 2. Enable the NVIC controller 3. Configure the GPIO correctly 4. Enable the USART "USART_InitTypeDef" contents properly 4. Ensure you have the ISRs implemented
P.S. I tried to supply code, but it was too long to accept: verbose.
P.P.S. Forum improvement: allow for attachments? or would that be really hard to do?
Hi readers,
I also posted on the http://www.st.com forum which finally helped me out. It turned out that I had to enable the Alternate Function clock but beneath that I made an and/or error setting the stopbits making all bits in register CR2 being set. But now: it runs!
Thanks everyone.
We are all happy that my advise helped.
Burp.
Of course i meant advice.
Of course i meant i'm an idiot.