I am a beginner, I am programming a stm32F411RE with Keil 5, when I was configuring the USART transmitter, Hercules and Arduino did not show any data, I reviewed several videos and I have the same problem, it has been several days. Thanks community.
#include <stm32f4xx.h>
void delay(int tiempo);
void USART2_Config();
void USART2_SendChar(uint8_t c);
int main(){
USART2_Config();
while(1){
USART2_SendChar('A');
delay(1000);
}
}
void USART2_Config(){
RCC->APB1ENR |= (1<<17); //Enable USART CLK
RCC->AHB1ENR |= (1<<0); //Enable GPIOA CLK
GPIOA->MODER |= (2<<4); //Alternate Function for Pin PA2
GPIOA->MODER |= (2<<6); //Alternate Function for Pin PA3
GPIOA->OSPEEDR|=(3>>4)|(3>>6); // High Speed for PIN PA2 and PA3
GPIOA->AFR[0] = (7<<8); // AF7 Alternate function USART2 at Pin PA2
GPIOA->AFR[0] = (7<<12); // AF7 Alternate function USART2 at Pin PA3
USART2->CR1 |= 0x00; // clear all
USART2->CR1 |= (1<<13);// USART ENABLE
USART2->CR1 |= ~(0>>12); //M = 0; 8 bits word length
USART2->BRR |= (8<<0)| (325<<4); // baud rate register 9600
USART2->CR1 |= (1<<2); // RX
USART2->CR1 |= (1<<3); // TX
}
void USART2_SendChar(uint8_t c){
USART2 -> DR = c;
while(!(USART2->SR & (1<<6)));
}
void delay(int tiempo){
int i;
for(;tiempo>0;tiempo--){
for(i=0;i<=3195;i++);
}
}