2023-08-23 01:35 AM
Hello,
I am trying to use UART HAL with the stm32-f030r8 connected to the PC through a USB-TTL module.
The configuration is given below :
- The F030R8 has JP1 OFF, JP6 ON, JP5 on E5V.
- The USB-TTL is :
- The code is :
/* Includes ------------------------------------------------------------------*/
#include "main.h"
uint8_t test[] = "hello";
UART_HandleTypeDef huart2;
int main(void)
{
HAL_Init();
SystemClock_Config();
__USART2_CLK_ENABLE();
__GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_PIN_2;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Alternate = GPIO_AF1_USART2;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_3;
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
huart2.Instance = USART2;
huart2.Init.BaudRate = 9600;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.Parity = UART_PARITY_NONE ;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.StopBits = UART_STOPBITS_1;
while (1){
HAL_UART_Transmit(&huart2,test,sizeof(test),HAL_MAX_DELAY);
HAL_Delay(1000);
}
}
Then, the putty configuration is 9600 baud, 8 data bits, 1 stop bits, no parity; no flow control.
But I can't see anything in the terminal...
Would you please have suggestions ?
Thanks for your help ! :)
2023-08-24 01:31 AM
Disconnect the 5v wire (RED) from the TTL module.
2023-08-24 01:59 AM
My last question refers to the configuration without TTL module. I put it below again :
As it is mentioned that "By default, the USART2 communication between the target STM32 and ST-LINK MCU is enabled", if we forget the USB-TTL module ie we have a unique wire (USB Type-A to Mini-B cable) between the PC and the stm32, do you know why is still have anything on putty ?
Configuration with JP1 OFF, JP6 ON and JP5 on U5V and the following code :
2023-08-24 03:58 AM - edited 2023-08-24 04:01 AM
On Nucleo (and Disco/EVAL), always start with reading the manual and looking at schematics for jumpers/solder bridges (SBxx) settings.
But maybe instead of changing the SB settings, you might want to leave them for the PA2/PA3 being used through the on-board STLink's VCP; and if you want for some reason to use the additional external USB-UART connection, use different pins/UART.
Also, as others said, you have to cross-connect the cable, Rx to Tx and vice versa (unless the USB-UART converter's author mislabelled the wires).
JW