cancel
Showing results for 
Search instead for 
Did you mean: 

I want to add jason parser using UART in my stm32 code. I used json.c and json.h files in the code. I can get the output in the compile time. But when I use run time I am not getting the output logically. Kindly help me.

Mmani.11
Associate

callback:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

   uint8_t i;

   if (huart->Instance == USART1)   //current UART

      {

      if (Rx_indx==250) {for (i=0;i<100;i++) Rx_Buffer[i]=0;}   //clear Rx_Buffer before receiving new data

      if (Rx_data[0]!=13)   //if received data different from ascii 13 (enter)

         {

         Rx_Buffer[Rx_indx++]=Rx_data[0];   //add data to Rx_Buffer

         }

      else         //if received data = 13

         {

         Rx_indx=0;

         Transfer_cplt=1;//transfer complete, data is ready to read

         }

      HAL_UART_Receive_IT(&huart1, Rx_data, 1);   //activate UART receive interrupt every time

      }

}

main.c

 HAL_UART_Receive_IT(&huart1, Rx_data, 1);   //activate uart rx interrupt avery time receiving 1 byte

while (1)

 {

   /* USER CODE END WHILE */

   /* USER CODE BEGIN 3 */

    i = 0;

         if (Transfer_cplt != 0)

            {

            //HAL_UART_Transmit(&huart1, "t", 1, 1000);

            for(int a=0;a<13;a++)

            {

            HAL_UART_Transmit(&huart1, Rx_Buffer, strlen(Rx_Buffer), 1000);

            JSONObject *json = parseJSON(Rx_Buffer);

            //HAL_UART_Receive(&huart1, json, strlen(json), 1000);

            printf(" %s : %s\r\n", json->pairs[a].key, json->pairs[a].value->stringValue);

Transfer_cplt=0;      //reset transfer_complete variable

               HAL_Delay(500);

               i++;

            }

          i = 1;

     }

0 REPLIES 0