Can't send data through the USART Tx Pin in the STM32F411E-Disco Board
#include "stm32f4xx.h" // Device header
void USART2_Init(void);
void USART2_Write(int ch);
void delayMS(int delay);
int main(void){
USART2_Init();
while(1){
USART2_Write('H');
USART2_Write('i');
delayMS(1000);
}
}
void USART2_Init(void){
RCC->APB1ENR |= 0x00020000;
RCC->AHB1ENR |= 0x00000001;
GPIOA->AFR[1] = 0x00000070;
GPIOA->MODER |= 0x00000020;
USART2->BRR = 0x342;
USART2->CR1 |= 0x00000008;
USART2->CR1 |= 0x00002000;
}
void USART2_Write(int ch){
while(!(USART2->SR & 0x0080)){
USART2->DR = (ch & 0xFF);
}
}
void delayMS(int delay){
int i;
for(; delay>0; delay--){
for(i = 0; i < 1000; i++);
}
}I am trying to Initialize and send data through PA3 (USART2_TX). When i connect the pin to a Serial to USB module to see the data sent on the terminal (CoolTerm) I get an error and doesnt' work. I set the baud rate based on that I have an 8MHz crystal on the board and still nothing is working. What is wrong in the code?