AnsweredAssumed Answered

How HAL_UART_Receive_IT() works?

Question asked by Maunik Patel on Jun 11, 2018
Latest reply on Jun 11, 2018 by Clive Two.Zero
I would like to know exactly how HAL_UART_Receive_IT() API works ...?


I am using STM32L432KB controller with Quectel's BG96 module to send AT commands and receive its variable length responses.
A demo code of my work is given below.
uint8_t ATE[] = "ATE0\r";
char buf[100], ch;
int i=0;

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
    if(huart->Instance == USART1){
    buf[i] = ch;               // filling 'buf', index by index, by 'ch', which has been received from main()
    HAL_UART_Receive_IT(&huart1, (uint8_t*)&ch, 1);

int main(){
      HAL_UART_Transmit(&huart1,(uint8_t *)ATE, sizeof(ATE),1000);   // turn Echo OFF for AT commands
      // HAL_UART_Receive(&huart1, (uint8_t*)&buf, sizeof(buf), 1000);   // if using this API, I can read the response in 'buf', but it takes 1 sec to receive about10 bytes
                                                                                                                 // @115200 buad.
                                                                                                                 // except this demo, I can't judge how much bytes I am about to receive
      HAL_UART_Receive_IT(&huart1, (uint8_t*)&ch,  1);                        // receiving one byte and storing it in 'ch'
      while(!strstr(buf, "OK")){                                                                     // waiting to get full response of AT command, so that it can be used for ERROR handling
While following this approach to develop my application I am getting many unpredictable results.
Can you help me to figure out what is wrong in this approach and how can I receive any variable length string in minimal time ?

Thank You,
Maunik Patel