Question
Uart usage with STM32F411RE Nucleo
Hello everyone I'm working with Uart on STM32F411RE Nucleo board. It gives a code error, but no data is provided through USART2. Can anyone help me with this problem? The code is as follows:
void Delay(int time);
static void uart_set_baudrate(uint32_t periph_clk, uint32_t baudrate);
static uint16_t compute_uart_bd(uint32_t periph_clk, uint32_t baudrate);
static void Uart_Write(int ch); int __io_putchar(int ch)
{ Uart_Write(ch);
return ch; }
int main(void)
{
RCC->AHB1ENR |= (1U<<0);
GPIOA->MODER &= ~(1U<<4);
GPIOA->MODER |= (1U<<5);
GPIOA->AFR[0] |= (1U<<8);
GPIOA->AFR[0] |= (1U<<9);
GPIOA->AFR[0] |= (1U<<10);
GPIOA->AFR[0] &=~ (1U<<11);
RCC->APB1ENR |= (1U<<17);
uart_set_baudrate(16000000, 115200);
USART2->CR1 = (1U<<3);
USART2->CR1 |= (1U<<13);
while(1)
{
printf("hello\n\r");
for(int i=0; i<100000; i++)
{} //Delay(10);
}
}
void Delay(int time)
{
for(int i; time>0; time--)
{
for(i=0; i<9600; i++)
{
}
}
}
static void Uart_Write(int ch)
{
while(!(USART2->SR & (1U<<7)))
{};
USART2->DR = (ch & 0xFF);
}
static uint16_t compute_uart_bd(uint32_t periph_clk, uint32_t baudrate)
{
return ((periph_clk + (baudrate/2U))/baudrate);
} static void uart_set_baudrate(uint32_t periph_clk, uint32_t baudrate)
{
USART2->BRR = compute_uart_bd(periph_clk, baudrate);
}
Edited (tradition to English)
