Skip to main content
SWenn.1
Senior III
April 23, 2023
Solved

nucleo-wb55rg and uart?

  • April 23, 2023
  • 2 replies
  • 1482 views

I have the following code where the variable string takes on the float value toPC correctly. I step into the HAL_UART_Transmit_IT and step over all the assignments and all looks fine yet I never see the TDR register update with the first value. Furthermore my while loop just hangs. Should I be doing something else for the uart to send data??

I am connected to the STLINK port on the board and have the UART configured for 19200, 8 bit, No parity and I see nothing come over the port. The TE, RE, UE and TXEIE bits in CR register are all set.

Thank you

		 for (uint8_t k = 0; k < NO_ADC_CH; k++)
		 {
			 static char string[7];
			 ISR.usart_txToPC = F;
			 /*
			 * LMT87 linear equation
			 * T = V - 2.6355 / -13.5mV
			 * equation represents 0C - 50C
			 */
			 float toPC =(((float)(stream[k]) / 4095 * 3.3) - 2.6355) / (-0.0135);
 
			 sprintf(string, "%2.2f\r\n", toPC);
			 HAL_UART_Transmit_IT(&huart1, (uint8_t*)string, strlen(string));
			 while(!ISR.usart_txToPC);
		 }
 

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
	if (huart == &huart1)
	{
		ISR.usart_txToPC = T;
	}
}

This topic has been closed for replies.
Best answer by Guenael Cadier

Hi @SWenn.1​ 

HAL_UART_Transmit_IT() function initiates the transmission in interrupt mode : at the end the TXE interrupt is enabled and when this interrupt will be fired TDR will be loaded with data to be transmitted.

So, at the end of HAL_UART_Transmit_IT() nothing is really started. You could exit with HAL_OK code, but this result does not indicate that transfer has been successfully achieved, only TxComplete callback will do that.

So in your case, a possible root cause could be that IRQ associated to your USART/UART instance you are using is not enabled.

For reference, you could find an example of a project transmitting data to a PC Hyperterminal in Interrupt mode on a STM32WB device here.

In above mentioned example (where USART1 is used), aside for Clock are GPIO intialisation, you could check code in HAL_UART_MspInit() function :

 /* USART1 interrupt Init */
 HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(USART1_IRQn);

Hope this helps.

2 replies

Guenael Cadier
Guenael CadierBest answer
ST Employee
April 25, 2023

Hi @SWenn.1​ 

HAL_UART_Transmit_IT() function initiates the transmission in interrupt mode : at the end the TXE interrupt is enabled and when this interrupt will be fired TDR will be loaded with data to be transmitted.

So, at the end of HAL_UART_Transmit_IT() nothing is really started. You could exit with HAL_OK code, but this result does not indicate that transfer has been successfully achieved, only TxComplete callback will do that.

So in your case, a possible root cause could be that IRQ associated to your USART/UART instance you are using is not enabled.

For reference, you could find an example of a project transmitting data to a PC Hyperterminal in Interrupt mode on a STM32WB device here.

In above mentioned example (where USART1 is used), aside for Clock are GPIO intialisation, you could check code in HAL_UART_MspInit() function :

 /* USART1 interrupt Init */
 HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(USART1_IRQn);

Hope this helps.

SWenn.1
SWenn.1Author
Senior III
April 25, 2023

Thank you....Very good explanation!