ESP32-C3-DevKitC-02 Getting Junk Data over UART
Posted: 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
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
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_system.h"
- #include "esp_log.h"
- #include "driver/uart.h"
- #include "string.h"
- #include "driver/gpio.h"
- static const int RX_BUF_SIZE = 1024;
- #define TXD_PIN (GPIO_NUM_21)
- #define RXD_PIN (GPIO_NUM_20)
- #define OK 1
- #define NOK 0
- void uart_init(void)
- {
- const uart_config_t uart_config = {
- .baud_rate = 115200,
- .data_bits = UART_DATA_8_BITS,
- .parity = UART_PARITY_DISABLE,
- .stop_bits = UART_STOP_BITS_1,
- .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
- .source_clk = UART_SCLK_DEFAULT,
- };
- // We won't use a buffer for sending data.
- uart_driver_install(UART_NUM_0, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
- uart_param_config(UART_NUM_0, &uart_config);
- uart_set_pin(UART_NUM_0, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
- }
- int sendData( const char *data)
- {
- static const char *TX_TASK_TAG = "TX_TASK";
- esp_log_level_set(TX_TASK_TAG, ESP_LOG_VERBOSE);
- const int len = strlen(data);
- const int txBytes = uart_write_bytes(UART_NUM_0, data, len);
- ESP_LOGI(TX_TASK_TAG, "Wrote %d bytes", txBytes);
- return txBytes;
- }
- static uint8_t receiveData(uint8_t *data,unsigned int delay_ms)
- {
- uint8_t rxBytes = 0;
- static const char *RX_TASK_TAG = "RX_TASK";
- esp_log_level_set(RX_TASK_TAG, ESP_LOG_VERBOSE);
- rxBytes = uart_read_bytes(UART_NUM_0, data,RX_BUF_SIZE, delay_ms / portTICK_PERIOD_MS);
- data[rxBytes]='\0';
- ESP_LOGI(RX_TASK_TAG, "Received %d bytes:\nRxData:%s\n", rxBytes,data);
- return rxBytes;
- }
- void app_main(void)
- {
- uint8_t *data = (uint8_t *)malloc(RX_BUF_SIZE + 1);
- uint8_t len=0;
- static const char *MAIN_TAG = "MAIN_FUNCTION";
- esp_log_level_set(MAIN_TAG, ESP_LOG_VERBOSE);
- memset(data, 0, RX_BUF_SIZE + 1);
- uart_init();
- vTaskDelay(20);
- uart_flush(UART_NUM_0);
- sendData("AT\r\n");
- len = receiveData(data,2000);
- if(OK == check_response(data,(unsigned char*)"OK"))
- {
- ESP_LOGI(MAIN_TAG,"AT Response Received");
- }
- else
- {
- ESP_LOGI(MAIN_TAG,"AT Response Not Received");
- }
- }