2022-10-01 03:34 AM
Hi,
I'm having trouble getting serial data out of my STM32 Nucleo board. I managed to get this working a few years ago but for some reason it's not working for me now.
The board that I'm using is an NUCLEO-F413ZH and I'm using a USB-TTL serial cable (TTL-232R-3V3) to try and print some test data to a hyper terminal (RealTerm).
I'm running the UART_printf example from the STM32CubeF4 firmware and have modified the code as shown below:
main.c
uint8_t test_str[] = "Hello World And The Universe!\r\n";
while (1)
{
HAL_UART_Transmit(&UartHandle, test_str, sizeof(test_str), 10);
HAL_Delay(1000);
}
main.h
#define USARTx USART2
#define USARTx_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE();
#define USARTx_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define USARTx_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define USARTx_FORCE_RESET() __HAL_RCC_USART2_FORCE_RESET()
#define USARTx_RELEASE_RESET() __HAL_RCC_USART2_RELEASE_RESET()
#define USARTx_TX_PIN GPIO_PIN_2
#define USARTx_TX_GPIO_PORT GPIOA
#define USARTx_TX_AF GPIO_AF7_USART2
#define USARTx_RX_PIN GPIO_PIN_3
#define USARTx_RX_GPIO_PORT GPIOA
#define USARTx_RX_AF GPIO_AF7_USART2
I have the serial cable hooked up as follows:
NUCLEO-F413ZH TTL-232R-3V3
Pin A2 Yellow wire
Pin A3 Orange wire
GND Black wire
These are the COM Port settings I am using:
TTL-232-3V3 RealTerm
COM3 Port: 3
Bits per second: 9600 Baud: 9600
Data bits: 7 Data bits: 7
Parity: Odd Parity: Odd
Stop bit: 1 Stop Bits: 1
Flow control: None Flow control: None
When I run the code, LD4 on the NUCLEO is flashing away indicating transmission, but there is no activity at all in the terminal.
My PC is running Windows 11.
Can anyone help me with this?
Cheers,
Tony
Solved! Go to Solution.
2022-10-07 02:50 AM
Got the code working. I found this tutorial which was super helpful:
Nucleo UART Tutorial | DMC, Inc. (dmcinfo.com)
I'm pretty sure I was just hooked up to the wrong pins but it was beneficial to learn how to use CubeMX to make the setup easier.
Thanks for your help.
2022-10-01 03:40 AM
Fixed this code but still no joy:
#define USARTx_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USARTx_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
2022-10-01 04:30 AM
Check the baudrate setting in your code (if it is set as 9600 as your hyper term) and the AF function, GPIO, Clock settings....
2022-10-07 02:50 AM
Got the code working. I found this tutorial which was super helpful:
Nucleo UART Tutorial | DMC, Inc. (dmcinfo.com)
I'm pretty sure I was just hooked up to the wrong pins but it was beneficial to learn how to use CubeMX to make the setup easier.
Thanks for your help.
2022-10-07 02:52 AM
See above