2026-06-04 7:05 PM
From my understanding im doing everything right im using a stm32f446re. Ive tried using cube ide where all the peripherals are loaded for me and it still doesnt seem to transmit i cannot see anything in the Putty or even the stm32 console. someone please help me understand
#include "Registers.h"
#define USART2_SR *(volatile uint32_t *) (USART2_BASE + 0x00U)
//Data Register (The mailbox slot where you load characters)
#define USART2_DR *(volatile uint32_t *) (USART2_BASE + 0x04U)
//Baud Rate Register (Controls transmission speed)
#define USART2_BRR *(volatile uint32_t *) (USART2_BASE + 0x08U)
//Control Register 1 (The main power and pin enable dashboard
#define USART2_CR1 *(volatile uint32_t *) (USART2_BASE + 0x0CU)
void init_uart()
{
RCC_APB1ENR |= (1U<<17);
GPIOA_MODER &= ~(3 << 2*2);
GPIOA_MODER |= (2U << 2*2);
GPIOA_AFRL &= ~(0xF<<2*4);
GPIOA_AFRL |= (7<<2*4);
USART2_BRR = 0x08B;
USART2_CR1 |= (1U<<13);
USART2_CR1 |= (1U<<3);
}
void uart_send_byte(uint8_t data)
{
// Wait until the Transmit Data Register Empty (TXE) flag is set
// TXE is Bit 7 in the Status Register (USART2_SR)
while (!(USART2_SR & (1U << 7)))
{
// Do nothing until the hardware is ready for the next byte
}
// Stuff the byte into the mailbox slot
USART2_DR = data;
}
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.