cancel
Showing results for 
Search instead for 
Did you mean: 

I am working on usart and I need to know the configuration for the code. Can someone check this and let me know if this config is correct or not. 9600 baud rate with 1 stop bit and no parity. I am working on usart1 which is connected to pb6 ( TX )

VSrin
Associate II

void sendchar(char c)

{

USART1->TDR = c;

while(!(USART1->ISR & USART_ISR_TC));

}

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_USART1_UART_Init();

 while (1)

 {

sendchar('a');

 }

}

// gpio config for pb6 (tx)

/*Transmission Pin */

 GPIO_InitStruct.Pin = usart_Pin;

 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

 GPIO_InitStruct.Alternate = GPIO_AF0_USART1;

 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

1 REPLY 1

Lacking any sort of context here.

What STM32 part, specifically, they make several hundred different ones.

Show the code initializing the USART, and perhaps the MSP code generated for that.

PB6 would need to define the Pin, and use GPIOB rather than GPIOA.

I would front test for TXE rather than back test for TC on the USART status.

Check that the GPIOB and USART1 clocks are enabled.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..