ESP32-C3-DevKitC-02 Getting Junk Data over UART

narayan
Posts: 1
Joined: Sat Jan 28, 2023 12:24 pm

ESP32-C3-DevKitC-02 Getting Junk Data over UART

Postby narayan » Sat Jan 28, 2023 12:39 pm

I have ESP32-C3-DevKitC-02 interfaced with SIMA7672S 4G module over UART0,when we send AT command from the ESP module, I am getting junk response ,I have tested SIMA7672S module with arduino it works fine over there, i dont see any junk in that case.
With ESP only I am seeing junk data,Is there any setting which i am missing?

Output:
I (2468) TX_TASK: Wrote 9 bytes
I (4478) RX_TASK: Received 197 bytes:
RxData:��mm����}�W��?�������_OM_}V}��_����{������M�o��_��{k���o�?��o��k��X����:���;'��=7
��jzkny���/�k��{z���o���{�����{�o��o���K�ko
INCORPORATED
OK

Whereas the expected output is only INCORPORATED OK

  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "esp_system.h"
  4. #include "esp_log.h"
  5. #include "driver/uart.h"
  6. #include "string.h"
  7. #include "driver/gpio.h"
  8.  
  9. static const int RX_BUF_SIZE = 1024;
  10.  
  11. #define TXD_PIN (GPIO_NUM_21)
  12. #define RXD_PIN (GPIO_NUM_20)
  13. #define OK      1
  14. #define NOK     0
  15.  
  16. void uart_init(void)
  17. {
  18.     const uart_config_t uart_config = {
  19.         .baud_rate = 115200,
  20.         .data_bits = UART_DATA_8_BITS,
  21.         .parity = UART_PARITY_DISABLE,
  22.         .stop_bits = UART_STOP_BITS_1,
  23.         .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
  24.         .source_clk = UART_SCLK_DEFAULT,
  25.  
  26.     };
  27.     // We won't use a buffer for sending data.
  28.     uart_driver_install(UART_NUM_0, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
  29.     uart_param_config(UART_NUM_0, &uart_config);
  30.     uart_set_pin(UART_NUM_0, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
  31. }
  32. int sendData( const char *data)
  33. {
  34.     static const char *TX_TASK_TAG = "TX_TASK";
  35.     esp_log_level_set(TX_TASK_TAG, ESP_LOG_VERBOSE);
  36.     const int len = strlen(data);
  37.     const int txBytes = uart_write_bytes(UART_NUM_0, data, len);
  38.     ESP_LOGI(TX_TASK_TAG, "Wrote %d bytes", txBytes);
  39.     return txBytes;
  40. }
  41.  
  42. static uint8_t receiveData(uint8_t *data,unsigned int delay_ms)
  43. {
  44.     uint8_t rxBytes = 0;
  45.     static const char *RX_TASK_TAG = "RX_TASK";
  46.     esp_log_level_set(RX_TASK_TAG, ESP_LOG_VERBOSE);
  47.  
  48.     rxBytes = uart_read_bytes(UART_NUM_0, data,RX_BUF_SIZE, delay_ms / portTICK_PERIOD_MS);
  49.     data[rxBytes]='\0';
  50.     ESP_LOGI(RX_TASK_TAG, "Received %d bytes:\nRxData:%s\n", rxBytes,data);
  51.    
  52.     return rxBytes;
  53. }
  54. void app_main(void)
  55. {
  56.     uint8_t *data = (uint8_t *)malloc(RX_BUF_SIZE + 1);
  57.     uint8_t len=0;
  58.     static const char *MAIN_TAG = "MAIN_FUNCTION";
  59.     esp_log_level_set(MAIN_TAG, ESP_LOG_VERBOSE);
  60.     memset(data, 0, RX_BUF_SIZE + 1);
  61.     uart_init();
  62.     vTaskDelay(20);
  63.     uart_flush(UART_NUM_0);
  64.  
  65.     sendData("AT\r\n");
  66.     len = receiveData(data,2000);
  67.    
  68.     if(OK == check_response(data,(unsigned char*)"OK"))
  69.     {
  70.         ESP_LOGI(MAIN_TAG,"AT Response Received");
  71.     }
  72.     else
  73.     {
  74.         ESP_LOGI(MAIN_TAG,"AT Response Not Received");
  75.     }
  76. }
Attachments
Capture.PNG
Output Image
Capture.PNG (9.84 KiB) Viewed 479 times

Who is online

Users browsing this forum: spenderIng and 153 guests