diff --git a/RotaxMonitor/lib/ADS1256/ADS1256.cpp b/RotaxMonitor/lib/ADS1256/ADS1256.cpp index 9467dd7..13ab8e1 100644 --- a/RotaxMonitor/lib/ADS1256/ADS1256.cpp +++ b/RotaxMonitor/lib/ADS1256/ADS1256.cpp @@ -89,10 +89,6 @@ void ADS1256::InitializeADC() digitalWrite(m_SYNC_pin, HIGH); // RESET is set to high } -#ifndef ADS1256_SPI_ALREADY_STARTED // Guard macro to allow external initialization of the SPI - _spi->begin(); -#endif - // Applying arbitrary default values to speed up the starting procedure if the user just want to get quick readouts // We both pass values to the variables and then send those values to the corresponding registers delay(200); diff --git a/RotaxMonitor/src/isr.h b/RotaxMonitor/src/isr.h index 1f1d2e7..737d1a3 100644 --- a/RotaxMonitor/src/isr.h +++ b/RotaxMonitor/src/isr.h @@ -16,7 +16,7 @@ #define CORE_0 0 #define CORE_1 1 -#define RT_TASK_STACK 2048 // in words +#define RT_TASK_STACK 4096 // in words #define RT_TASK_PRIORITY (configMAX_PRIORITIES - 5) // highest priority after wifi tasks struct isrParams diff --git a/RotaxMonitor/src/main.cpp b/RotaxMonitor/src/main.cpp index cd46365..0b04eeb 100644 --- a/RotaxMonitor/src/main.cpp +++ b/RotaxMonitor/src/main.cpp @@ -17,7 +17,7 @@ #include // Defines to enable channel B -// #define CH_B_ENABLE +#define CH_B_ENABLE // Debug Defines #define WIFI_SSID "AstroRotaxMonitor" @@ -27,12 +27,13 @@ void setup() { - Serial.begin(921600); + Serial.begin(115200); delay(250); + Serial.setTimeout(30000); // Setup Logger LOG_ATTACH_SERIAL(Serial); - LOG_SET_LEVEL(DebugLogLevel::LVL_INFO); + LOG_SET_LEVEL(DebugLogLevel::LVL_DEBUG); // Print Processor Info LOG_DEBUG("ESP32 Chip:", ESP.getChipModel()); @@ -47,27 +48,27 @@ void setup() LOG_DEBUG("ESP32 Sketch:", ESP.getFreeSketchSpace()); // Init Wifi station - LOG_INFO("Initializing WiFi..."); - WiFi.mode(WIFI_AP); - IPAddress local_IP(10, 11, 12, 1); - IPAddress gateway(10, 11, 12, 1); - IPAddress subnet(255, 255, 255, 0); - WiFi.softAPConfig(local_IP, gateway, subnet); - WiFi.setTxPower(WIFI_POWER_5dBm); // reduce wifi power - if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD)) - { - LOG_INFO("WiFi AP Mode Started"); - LOG_INFO("Wifi SSID:", WIFI_SSID); - LOG_INFO("Wifi Password:", WIFI_PASSWORD); - LOG_INFO("WiFi IP:" + WiFi.softAPIP().toString()); - } - else - { - LOG_ERROR("Failed to start WiFi AP Mode"); - LOG_ERROR("5 seconds to restart..."); - vTaskDelay(pdMS_TO_TICKS(5000)); - esp_restart(); - } + // LOG_INFO("Initializing WiFi..."); + // WiFi.mode(WIFI_AP); + // IPAddress local_IP(10, 11, 12, 1); + // IPAddress gateway(10, 11, 12, 1); + // IPAddress subnet(255, 255, 255, 0); + // WiFi.softAPConfig(local_IP, gateway, subnet); + // WiFi.setTxPower(WIFI_POWER_5dBm); // reduce wifi power + // if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD)) + // { + // LOG_INFO("WiFi AP Mode Started"); + // LOG_INFO("Wifi SSID:", WIFI_SSID); + // LOG_INFO("Wifi Password:", WIFI_PASSWORD); + // LOG_INFO("WiFi IP:" + WiFi.softAPIP().toString()); + // } + // else + // { + // LOG_ERROR("Failed to start WiFi AP Mode"); + // LOG_ERROR("5 seconds to restart..."); + // vTaskDelay(pdMS_TO_TICKS(5000)); + // esp_restart(); + // } // Initialize Interrupt pins on PICKUP detectors initTriggerPinsInputs(); @@ -91,17 +92,36 @@ void loop() //////// INIT SPI INTERFACES //////// bool spiA_ok = true; bool spiB_ok = true; + //////// INIT SPI INTERFACES //////// LOG_DEBUG("Init SPI Interfaces"); SPIClass SPI_A(FSPI); spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI); SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1 LOG_DEBUG("Init SPI A ok"); -#ifdef CH_B_ENABLE - delay(50); + Serial.readStringUntil('\n'); + dev->m_spi_a.reset(&SPI_A); + dev->m_adc_a = std::make_unique(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A); + dev->m_adc_a->InitializeADC(); + dev->m_adc_a->setPGA(PGA_1); + dev->m_adc_a->setDRATE(DRATE_7500SPS); + LOG_DEBUG("Init ADC A ok"); + Serial.readStringUntil('\n'); + + delay(250); + + #ifdef CH_B_ENABLE SPIClass SPI_B(HSPI); spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI); SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1 LOG_DEBUG("Init SPI B ok"); + Serial.readStringUntil('\n'); + dev->m_spi_b.reset(&SPI_B); + dev->m_adc_b = std::make_unique(ADC_B_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_B_CS, 2.5, &SPI_B); + dev->m_adc_b->InitializeADC(); + dev->m_adc_b->setPGA(PGA_1); + dev->m_adc_b->setDRATE(DRATE_7500SPS); + LOG_DEBUG("Init ADC B ok"); + Serial.readStringUntil('\n'); #endif if (!spiA_ok || !spiB_ok) @@ -111,37 +131,23 @@ void loop() vTaskDelay(pdMS_TO_TICKS(5000)); esp_restart(); } - dev->m_spi_a.reset(&SPI_A); -#ifdef CH_B_ENABLE - dev->m_spi_b.reset(&SPI_B); -#endif - // Init ADCs - dev->m_adc_a = std::make_unique(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A); -#ifdef CH_B_ENABLE - dev->m_adc_b = std::make_unique(ADC_B_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_B_CS, 2.5, &SPI_B); -#endif - // Configure ADCs - dev->m_adc_a->InitializeADC(); - dev->m_adc_a->setPGA(PGA_1); - dev->m_adc_a->setDRATE(DRATE_7500SPS); -#ifdef CH_B_ENABLE - dev->m_adc_b->InitializeADC(); - dev->m_adc_b->setPGA(PGA_1); - dev->m_adc_b->setDRATE(DRATE_30000SPS); -#endif + LOG_DEBUG("Init SPI OK"); + Serial.readStringUntil('\n'); //////// INIT I2C INTERFACES //////// - LOG_DEBUG("Init I2C Interfaces"); - bool i2c_ok = true; - i2c_ok = Wire.begin(SDA, SCL, 100000); - if (!i2c_ok) - { - LOG_ERROR("Unable to Initialize I2C Bus"); - LOG_ERROR("5 seconds to restart..."); - vTaskDelay(pdMS_TO_TICKS(5000)); - esp_restart(); - } + // LOG_DEBUG("Init I2C Interfaces"); + // bool i2c_ok = true; + // i2c_ok = Wire.begin(SDA, SCL, 100000); + // if (!i2c_ok) + // { + // LOG_ERROR("Unable to Initialize I2C Bus"); + // LOG_ERROR("5 seconds to restart..."); + // vTaskDelay(pdMS_TO_TICKS(5000)); + // esp_restart(); + // } + // LOG_DEBUG("Init I2c ok"); + // Serial.readStringUntil('\n'); // Init IO Expanders // dev->m_ext_io = std::make_unique(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT); @@ -212,7 +218,9 @@ void loop() //////// SPAWN REALTIME TASKS //////// auto task_A = rtIgnitionTask(taskA_params, PSRAM_MAX, QUEUE_MAX, CORE_0, fs_mutex); delay(50); + Serial.readStringUntil('\n'); auto task_B = rtIgnitionTask(taskB_params, PSRAM_MAX, QUEUE_MAX, CORE_1, fs_mutex); + Serial.readStringUntil('\n'); // Ignition A on Core 0 auto ignA_task_success = task_A.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;