2024-04-01 12:22 PM
Hi, I wonder has anyone experience with baremetal USART implementation as I have attached a Source file for USART for a 'STM32G0B1RET' discovery board but it just sits there and doesn't transmit anything? See attached (usart.c). I have basically just copied this from a working F4 board and modified it for a G0 board (assuming it would work!?)...
Solved! Go to Solution.
2024-04-01 02:01 PM - edited 2024-04-01 02:30 PM
> 'STM32G0B1RET' discovery board
Do you mean Nucleo board?
I compiled your code (commenting out SetSystemClockTo16Mhz() as you did not provide that function, but simply leaving the default HSI16 clock, that's 16MHz too), and on Nucleo I can see the transmitted data on PA2 (and also LED on PA5 blinking slowly).
JW
PS. You set USART2_BRR in USART1 setup, but you don't call that function here.
2024-04-01 02:01 PM - edited 2024-04-01 02:30 PM
> 'STM32G0B1RET' discovery board
Do you mean Nucleo board?
I compiled your code (commenting out SetSystemClockTo16Mhz() as you did not provide that function, but simply leaving the default HSI16 clock, that's 16MHz too), and on Nucleo I can see the transmitted data on PA2 (and also LED on PA5 blinking slowly).
JW
PS. You set USART2_BRR in USART1 setup, but you don't call that function here.
2024-04-02 12:42 PM
Hi JW,
Thanks for trying it out I have just had a closer look and something really odd is happening if you use "UART2_send" it transmits to UART1 TX (PC4) and if you use "UART1_send" it transmits to UART2 TX (PA2)? I can't workout why it's doing this as the UART send commands it clearly states the correct Registries:-
void UART1_send(char *msg, size_t len){
for (uint64_t i=0; i<len; i++)
{
// send character
USART1->TDR = msg[i];
// wait for transmit complete (ts)
while(!(USART1->ISR & (1 << 6)));
}
}
2024-04-02 12:52 PM
Hi JW, Now it explains as I used the incorrect pinouts and the pins where swapped! as below diagram (wrong one is at the bottom).
2024-04-02 01:22 PM
Thanks for coming back with the solution. Please click on "Accept as solution" in that post so that the thread is marked as solved.
Where is that incorrect picture from?
JW