cancel
Showing results for 
Search instead for 
Did you mean: 

UART2 doesn't sent data from TX

Takayoshi Ishii
Associate III
Posted on July 20, 2017 at 06:03

I made a program and it works well without UART2. I just made a simple program but nothing happend on the TX pin of the UART2.

while (1)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

displayBuffer[0]++;

updateLcd();

HAL_UART_Transmit(&huart2, &displayBuffer[0], 1, 0xFFFF);

tmp++;

HAL_Delay(1000);

}

'updateLcd()' function is using I2C and the clock source is same of UART2, so I think the clock for UART2 works. I2C works well.

TX line voltage continues hi, as idle. No data come up.

I can see the TDR resistor changes the value each 1 sec, so my data is stored in TDR for sure.

I tried to not use 

HAL_UART_Transmit() function and tried to write the data directly into the TDR like following, the result was same...

huart2.Instance->TDR = 

displayBuffer[0];

The periferal clock is 16MHz, and the UART2 setting is following.

/* USART2 init function */

static void MX_USART2_UART_Init(void)

{

huart2.Instance = USART2;

huart2.Init.BaudRate = 9600;

huart2.Init.WordLength = UART_WORDLENGTH_8B;

huart2.Init.StopBits = UART_STOPBITS_1;

huart2.Init.Parity = UART_PARITY_NONE;

huart2.Init.Mode = UART_MODE_TX_RX;

huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart2.Init.OverSampling = UART_OVERSAMPLING_16;

huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

if (HAL_UART_Init(&huart2) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Takayoshi Ishii
Associate III
Posted on July 31, 2017 at 06:17

I have tried to read reference many times, check the signals by oscilloscope, read sample code, check the schematic of NUCREO.

On the NUCREO board, the UART2 is connected to ST-Link, but it seems OK for use UART2 from outside.

But, I finally, I made my original circuit of STM32L051, then I could use UART2 by same code.

View solution in original post

8 REPLIES 8
Posted on July 20, 2017 at 06:13

Ok, so as presented I have no way of knowing what part is being used, and don't have enough code to replicate the issue.

Look at the pin initialization code, and that for the USART clock

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
Posted on July 20, 2017 at 09:30

Go in debug mode. Run the code and stop it after trying to send data. Open the STM32 HW UART registers and try manually to spit a byte out of TX. Check out the GPIO and RCC registers as well. You might find out what is missing in porting from one USART to another.

Takayoshi Ishii
Associate III
Posted on July 20, 2017 at 12:41

Thank you for reply.

I use Nucleo-L053R8 board.

I use CubeMX and I use PA2 and PA3 for the UART2. When I enable UART2 on the CubeMX, PA2 and PA3 will be the port. No choice. But there is another alies UART2 port on PA13 and PA14. PA13 and PA14 is connected as SWD port on the Nucleo bord.

I think I don't need set the GPIO setthing when I use UART. I read the reference manual of L0x and it says that, when I use UART TX, I have to set TE=1 and the TX pin will be idle state. This mean I don't have to set PA2 to output or someting. On the debugging, I can see the TE=1 and the PA2(TX) goes hi as idle status of UART. 

This is the GPIO setting code that Cube-MX generated.

static void MX_GPIO_Init(void)

{

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

__HAL_RCC_GPIOB_CLK_ENABLE();

}

I have stacked two days and I tried 

1) Run debug and trace all steps for the sending data program and functions. It seems no ploblem and the TDR value is changing that I as I expected. All flugs seems OK.

2) Bought another Nucleo board but the result is same.

3) Check all of the pin condition.

Takayoshi Ishii
Associate III
Posted on July 20, 2017 at 12:48

I use PA2 and PA3. The color is green that mean OK I think.

0690X00000607dnQAA.png
Posted on July 27, 2017 at 21:45

 ,

 ,

Hi ,Takayoshi Ishii,

What kind of data is stored in ,

displayBuffer[0], uint8, uint16..., and I would like to know how are you testing that the pin is sending ,nothing, did you check with an oscilloscope or just with a terminal? Maybe some information on this post could help to you:

https://community.st.com/0D70X000006SciuSAC

 ,
S.Ma
Principal
Posted on July 28, 2017 at 08:34

Start from an rs232 uart or usart sample code then modify step by step. Easier to do this way when getting familiar with the internal details of the reference manual...

Takayoshi Ishii
Associate III
Posted on July 31, 2017 at 06:17

I have tried to read reference many times, check the signals by oscilloscope, read sample code, check the schematic of NUCREO.

On the NUCREO board, the UART2 is connected to ST-Link, but it seems OK for use UART2 from outside.

But, I finally, I made my original circuit of STM32L051, then I could use UART2 by same code.

TMöll.2
Associate

UserManual UM1724

Chapter 6.8 USART communication

If the communication between the target STM32 PA2 (D1) or PA3 (D0) and shield or extension board is required, SB62 and SB63 must be ON, while SB13 and SB14 must be OFF.

You must move the 0Ohm resistors on the board bottom side.