cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Transmit_IT?? STM32F072

SWenn.1
Senior III

I have the following block of code. I am averaging 6 A/D inputs. Stream holds these 6 average values and looks fine. One at a time the loop converts each sample to ascii and appends '\n' and '\r' and then transmits them over the UART. If I use UART_Transmit as seen all looks fine (UART running at 115200). If however I try and use UART_Transmit_IT some samples do NOT transmit to the laptop the correct value (as I compare the Stream values to the laptop values). Can someone tell me why this command call isn't working correctly?

My expectation is I transmit a value + '\n' + '\r' . The code waits until done (HAL_OK) and then the loop continues and does the second piece of data and so on....

for (k = 0; k < NO_ADC_CH; k++)
 {
    test = hex2Ascii(stream + k);
//while (!(HAL_OK == HAL_UART_Transmit_IT(&huart2, test, 6)));
    HAL_UART_Transmit(&huart2, test, 6, 10);
  }

1 ACCEPTED SOLUTION

Accepted Solutions
SWenn.1
Senior III

Thank you! I wasn't clearing the ISR flag...now working​

View solution in original post

5 REPLIES 5
gbm
Lead III

What are the declarations of test, stream and k?

I suspect your problem has nothing to do with STM32. It's about understanding the C language and the difference between the concept of a variable in C and Python.

In C you cannot assign strings with = operator nor append a character representation of a number to a string using +.

In C "stream + k" is a pointer to the k-th character of string named stream.

Read the warnings issued by the compiler. Treat every warning as an error in your code.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
SWenn.1
Senior III

compiler gives no warnings compiles error free....

Does the HAL_UART_Transmit_IT give an interrupt after every character or will it hold off the IT until all 6 values have been transmitted?

uint16_t adc_buf[ADC_BUF_LEN], stream[NO_ADC_CH];
uint8_t k;
uint8_t *test;

SWenn.1
Senior III

As I said if I cycle thru loop test holds good values.....It seems the loop doesn't wait for the ...._IT and the loop just keeps cycling.....I've also tried the following but to no avail :

  for (k = 0; k < NO_ADC_CH; k++)
  {
	  while(ISR.UART_TxComplete);
	  test = hex2Ascii(stream + k);
	  HAL_UART_Transmit_IT(&huart2, test, 6);
//			  while (!(HAL_OK == HAL_UART_Transmit_IT(&huart2, test, 6)));
//			  HAL_UART_Transmit(&huart2, test, 6, 10);
  }
 
 
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
	ISR.UART_TxComplete = T;
}

gbm
Lead III

And what is hex2Ascii ? The problem results from this line:

test = hex2Ascii(stream + k);

Which is not doing what you want it to do, but what you ordered, which is not the same.

But i assume there is another problem or two - show the declaration of ISR.UART_TxComplete.

Do you ever set ISR.UART_TxComplete to 0?

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
SWenn.1
Senior III

Thank you! I wasn't clearing the ISR flag...now working​