2020-02-07 12:43 PM
I am currently learning to work with stm32f411re. I use PA9/10 as TX and RX with baud rate 9600 and 1 start 8 bit word and 1 stop without parity. I connected PA9/PA10 with FTDI to my PC and i am trying to send from serial terminal. Trying to do this with interrupts. As i can see from debugger it is entering into ISR, but its echoing wrong characters. 16Mhz RC oscillator was used as clk. No prescalers. Oversampling default (16). Thank you for your time
#include "stm32f4xx.h"
#include "system_stm32f4xx.h"
#define DELAY 0xFFFFFFFF
#define SEK 16000000
void USART1_IRQHandler (void) ;
int main() {
RCC->AHB1ENR|=(1<<0); //GPIOA
RCC->APB2ENR|=(1<<4); // Clock za USART1
GPIOA->MODER|=(1<<10);
GPIOA->MODER|=0x3;
GPIOA->MODER|=0x280000; //PA9 I PA10 ALTERNATIVE MODE
GPIOA->AFR[1]|=0x770; //0111 AF07
USART1->CR1|=(1<<13); //enable usart
USART1->BRR=0x683; //9600
USART1->CR1|=((1<<3) | (1<<2)); //TX I RX ENABLE
USART1->CR1|=(1<<5); //ENABLE USART INTERRUPT RECEIVE
__NVIC_EnableIRQ( USART1_IRQn );
USART1->DR='a';
while(1){
}
return 0;
}
void USART1_IRQHandler (void)
{
char c;
c=USART1->DR;
USART1->DR=c;
}
2020-02-07 01:09 PM
Need to set BRR before enabling USART in CR1
Don't expect you can just OR everything together.
2020-02-07 01:24 PM
Thank you for reply. This was one of many attempts to get this thing going. From start i tried with seting brr before enabling usart. Didnt help (tried it again minut ago). Which is the part exactly that you think i cant do OR operation on ?
2020-02-07 02:56 PM
Are you sure the mcu runs at 16MHz? Isn't there some code in startup changing clocks?
Instead of Rx in interrupt, start with a polled transmission of a known byte, e.g. 0x55 ('U') and observe it on the Tx pin using oscilloscope or logic analyzer.
JW