2025-01-17 03:10 PM
Hello there,
I've been stuck for hours on setting up a simple UART transmission of the character 'A' on my
Nucleo L053R8 Board.
Thing is, my oscilloscope does not show anything on my PA2 pin. It should be HIGH in idle state though.
Am I missing something, because this is a low power board and it needs special configuration?
My other fear is that I'm missing some linking options, since I'm not using HAL libaries and have configured
it myself. I've checked the registers like 100 times. Both pins PA2 and P3 are configured for AF4, just
as the datasheet says.
So here is my reduced code:
#include <stdint.h>
#include <ctype.h>
#include <stm32l053xx.h>
void UART2_Transmit(char data) {
while ((USART2->ISR & (1<<7)) == 0) {
}
USART2->TDR = data; // Write the character to the TDR register for transmission
}
int main(void){
/*Initialisierung GPIO + Takt*/
RCC->IOPENR |= RCC_IOPENR_GPIOAEN; // Anders auf diesem STM32 sonst AHBENR
RCC->IOPENR |= RCC_IOPENR_GPIOBEN; // Takt B Enable
RCC->IOPENR |= RCC_IOPENR_GPIOCEN; // Takt C Enable
GPIOA->MODER = 0xE8000000; //alles auf 0 bis auf PA13 und PA14, damit debugger tut
GPIOA->MODER |= (1 << 5); // PA3 als AF setzbar machen RX
GPIOA->MODER |= (1 << 7); // Setzt PA2 Alternate Function mode,
GPIOA->AFR[0] |= (1 << 14); // und PA3 AF setzen
GPIOA->AFR[0] |= (1 << 10); // PA2 als AF setzen
RCC->APB1ENR |= RCC_APB1ENR_USART2EN; // Takt USART enable
#define UART1_BAUD_RATE 9600
#define SYSTEM_TAKT 8000000
USART2->BRR = 833; // Baudrate setzen
USART2->CR1 = USART_CR1_UE | USART_CR1_RE | USART_CR1_TE;
for(;;){
UART2_Transmit('A');
UART2_Transmit('B');
UART2_Transmit('C');
}
}
My debugger does show that TDR is getting the correct values though, so
USART2 is definitely up and running.
Any help is highly appreciated.
2025-01-17 03:15 PM
Please get the user guide for your Nucleo board and check that the PA2, PA3 pins are free to use. They may be occupied by something else on the board.
2025-01-17 03:27 PM
Well, it does say the following:
USART communication
The USART2 interface available on PA2 and PA3 of the STM32 microcontroller can be
connected to ST-LINK MCU, ST morpho connector, or to ARDUINO® connector
It most certainly is configurable, I'm just missing something.
2025-01-17 03:52 PM
Try to configure PA2, PA2 as plain push-pull GPIOs and toggle from your code. Will you see this toggling on a scope?