cancel
Showing results for 
Search instead for 
Did you mean: 

nucleo-wb55rg and uart?

SWenn.1
Senior III

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;
	}
}

1 ACCEPTED SOLUTION

Accepted Solutions
Guenael Cadier
ST Employee

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.

View solution in original post

2 REPLIES 2
Guenael Cadier
ST Employee

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
Senior III

Thank you....Very good explanation!