USART error in STM32F4
Good evening community members,
today I have been trying to activate USART module of my STM32F446 board. However even after trying everything, I could not sense Tx signal on PA2 pin of the board. This is the low level code I used. I had been trying to capture the signal using Oscilloscope but got nothing. Could someone help me how to resolve the issue? I tried my best but found nothing so far. Thanks in advance.
#include "stm32f4xx.h"
#include <stdint.h>
#include <stdio.h>
void gpio_init(void)
{
RCC->APB1ENR |= (1U<<17); //enable clock for USART2
GPIOA->MODER |= (0b10<<4); //setting PA2 in alternate function mode
GPIOA->AFR[0] |= (0b0111<<8); //setting PA2 in AF7 mode
RCC->AHB1ENR |= (1U<<0); //enable GPIO Port A
}
void usart_init(void)
{
USART2->BRR = (0x8B); //setting baud rate as 115200
USART2->CR1 = (1U<<3); //transmitter enable
USART2->CR1 |= (1U<<13); //enable USART
}
void usart2_data(char c)
{
while (!(USART2->SR & (1U<<7))){}
USART2->DR = c;
}
#include <usart_tx.h>
int main(void)
{
gpio_init();
usart_init();
while (1)
{
usart2_data('Y');
}
}
