I decided I would try my hand at programming an ESP32 using CLion instead of the Arduino IDE, so this project is running in the ESP IDF (toolchain?) and C language. I couldn't find the file for setting the settings, so all pins and settings are default - it would fill out the whole post if I were to post them all, so feel free to ask me, if you suspect these settings might have anything to do with my error.
The actual MCU is an ESP32 WROVER-E connected to a SIM7600E module (see the whole board here: LILYGO® TTGO SIM7600E-H Module ESP32 from Lilygo on Tindie )
My code is the following:
My two modem-related functions are here:
When I run my main code, I get this output:
If I print the "data" array before reading bytes, it's just a bunch of random chars, so it appears that I am in fact reading off of the SIM7600E? Either way, I am lost.
The actual MCU is an ESP32 WROVER-E connected to a SIM7600E module (see the whole board here: LILYGO® TTGO SIM7600E-H Module ESP32 from Lilygo on Tindie )
My code is the following:
C:
//
// Created by DripTooHard on 31-12-2022.
//
#include "ATTest.h"
static const char *TAG = "UART TEST";
#define UART_PORT_NUM (2)
#define UART_ESP_TXD (27)
#define UART_ESP_RXD (26)
#define UART_ESP_RTS (UART_PIN_NO_CHANGE) //We don't have flow control for the Sim7600
#define UART_ESP_CTS (UART_PIN_NO_CHANGE)
#define ESP_BLINK_PIN (12) //Pin for lighting the esp
const uart_port_t uart_num = UART_NUM_1;
const int BUF_SIZE = 1024;
void turnOnpin(int PIN_NUMBER){
gpio_reset_pin(PIN_NUMBER);
gpio_set_direction(PIN_NUMBER, GPIO_MODE_OUTPUT);
gpio_set_level(PIN_NUMBER,1);
}
void getPinReady(int GPIO_MODE, int PIN_NUMBER){
gpio_reset_pin(PIN_NUMBER);
gpio_set_direction(PIN_NUMBER,GPIO_MODE);
}
void sendATCommand(void){
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,
}; int intr_alloc_flags = 0;
#if CONFIG_UART_ISR_IN_IRAM
intr_alloc_flags = ESP_INTR_FLAG_IRAM;
#endif
//Install driver, set communication settings and set communication pins
ESP_ERROR_CHECK(uart_driver_install(UART_PORT_NUM, BUF_SIZE * 2, 0, 0, NULL, intr_alloc_flags));
ESP_ERROR_CHECK(uart_param_config(UART_PORT_NUM, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(UART_PORT_NUM, UART_ESP_TXD, UART_ESP_RXD,UART_ESP_RTS, UART_ESP_CTS));
// Configure a temporary buffer for the incoming data
uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
//Power the modem
turnOnpin(ESP_BLINK_PIN);
getPinReady(GPIO_MODE_OUTPUT,25);
powerModem();
//UART doesn't function until we get status = high
waitForStatus();
// Command for getting module data
char * string = "Random stuff";
uart_write_bytes(UART_PORT_NUM, string,strlen(string));
uart_flush(UART_PORT_NUM);
int responseLength = 0;
// Read data from UART.
while(responseLength <1){
responseLength = uart_read_bytes(UART_PORT_NUM, data, &responseLength, 100);
}
printf("%d",responseLength);
printf("\n");
vTaskDelay(100);
for(int i = 0; i<responseLength;i++){
printf("%c",data[i]);
}
printf("\n");
}
void app_main(void)
{
sendATCommand();
//xTaskCreate(sendATCommand, "uart_echo_task", 2048, NULL, 10, NULL);
}
C:
//
// Created by DripTooHard on 31-12-2022.
//
#define UART_ECHO_MODEMCOMMANDS_H
#endif //UART_ECHO_MODEMCOMMANDS_H
#include "esp_err.h"
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "esp_log.h"
#define MODEM_PWR_PIN (4) //Pin on the ESP32 for powering the modem
#define MODEM_STATUS_PIN (34)// Pin on the ESP32 for checking status
void powerModem(void){
gpio_reset_pin(MODEM_PWR_PIN);
gpio_set_direction(MODEM_PWR_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(MODEM_PWR_PIN,1);
vTaskDelay(100);
gpio_set_level(MODEM_PWR_PIN,0);
}
int waitForStatus(void){
gpio_reset_pin(MODEM_STATUS_PIN);
gpio_set_direction(MODEM_STATUS_PIN, GPIO_MODE_INPUT);
int pin_status = gpio_get_level(MODEM_STATUS_PIN);
while(pin_status != 1){
printf("MODEM IS NOT READY");
pin_status = gpio_get_level(MODEM_STATUS_PIN);
vTaskDelay(5000/portTICK_PERIOD_MS); //Wait at increments of 5, as the typical time is 16
}
printf("MODEM STATUS: POWER ON\n");
return 1;
}
I (1370) gpio: GPIO[34]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
MODEM STATUS: POWER ON
12
Random stuff
I (3380) main_task: Returned from app_main()
If I print the "data" array before reading bytes, it's just a bunch of random chars, so it appears that I am in fact reading off of the SIM7600E? Either way, I am lost.