working on second adc
This commit is contained in:
@@ -89,10 +89,6 @@ void ADS1256::InitializeADC()
|
|||||||
digitalWrite(m_SYNC_pin, HIGH); // RESET is set to high
|
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
|
// 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
|
// We both pass values to the variables and then send those values to the corresponding registers
|
||||||
delay(200);
|
delay(200);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#define CORE_0 0
|
#define CORE_0 0
|
||||||
#define CORE_1 1
|
#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
|
#define RT_TASK_PRIORITY (configMAX_PRIORITIES - 5) // highest priority after wifi tasks
|
||||||
|
|
||||||
struct isrParams
|
struct isrParams
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <led.h>
|
#include <led.h>
|
||||||
|
|
||||||
// Defines to enable channel B
|
// Defines to enable channel B
|
||||||
// #define CH_B_ENABLE
|
#define CH_B_ENABLE
|
||||||
|
|
||||||
// Debug Defines
|
// Debug Defines
|
||||||
#define WIFI_SSID "AstroRotaxMonitor"
|
#define WIFI_SSID "AstroRotaxMonitor"
|
||||||
@@ -27,12 +27,13 @@
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(921600);
|
Serial.begin(115200);
|
||||||
delay(250);
|
delay(250);
|
||||||
|
Serial.setTimeout(30000);
|
||||||
|
|
||||||
// Setup Logger
|
// Setup Logger
|
||||||
LOG_ATTACH_SERIAL(Serial);
|
LOG_ATTACH_SERIAL(Serial);
|
||||||
LOG_SET_LEVEL(DebugLogLevel::LVL_INFO);
|
LOG_SET_LEVEL(DebugLogLevel::LVL_DEBUG);
|
||||||
|
|
||||||
// Print Processor Info
|
// Print Processor Info
|
||||||
LOG_DEBUG("ESP32 Chip:", ESP.getChipModel());
|
LOG_DEBUG("ESP32 Chip:", ESP.getChipModel());
|
||||||
@@ -47,27 +48,27 @@ void setup()
|
|||||||
LOG_DEBUG("ESP32 Sketch:", ESP.getFreeSketchSpace());
|
LOG_DEBUG("ESP32 Sketch:", ESP.getFreeSketchSpace());
|
||||||
|
|
||||||
// Init Wifi station
|
// Init Wifi station
|
||||||
LOG_INFO("Initializing WiFi...");
|
// LOG_INFO("Initializing WiFi...");
|
||||||
WiFi.mode(WIFI_AP);
|
// WiFi.mode(WIFI_AP);
|
||||||
IPAddress local_IP(10, 11, 12, 1);
|
// IPAddress local_IP(10, 11, 12, 1);
|
||||||
IPAddress gateway(10, 11, 12, 1);
|
// IPAddress gateway(10, 11, 12, 1);
|
||||||
IPAddress subnet(255, 255, 255, 0);
|
// IPAddress subnet(255, 255, 255, 0);
|
||||||
WiFi.softAPConfig(local_IP, gateway, subnet);
|
// WiFi.softAPConfig(local_IP, gateway, subnet);
|
||||||
WiFi.setTxPower(WIFI_POWER_5dBm); // reduce wifi power
|
// WiFi.setTxPower(WIFI_POWER_5dBm); // reduce wifi power
|
||||||
if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD))
|
// if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD))
|
||||||
{
|
// {
|
||||||
LOG_INFO("WiFi AP Mode Started");
|
// LOG_INFO("WiFi AP Mode Started");
|
||||||
LOG_INFO("Wifi SSID:", WIFI_SSID);
|
// LOG_INFO("Wifi SSID:", WIFI_SSID);
|
||||||
LOG_INFO("Wifi Password:", WIFI_PASSWORD);
|
// LOG_INFO("Wifi Password:", WIFI_PASSWORD);
|
||||||
LOG_INFO("WiFi IP:" + WiFi.softAPIP().toString());
|
// LOG_INFO("WiFi IP:" + WiFi.softAPIP().toString());
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
LOG_ERROR("Failed to start WiFi AP Mode");
|
// LOG_ERROR("Failed to start WiFi AP Mode");
|
||||||
LOG_ERROR("5 seconds to restart...");
|
// LOG_ERROR("5 seconds to restart...");
|
||||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
// vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
esp_restart();
|
// esp_restart();
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Initialize Interrupt pins on PICKUP detectors
|
// Initialize Interrupt pins on PICKUP detectors
|
||||||
initTriggerPinsInputs();
|
initTriggerPinsInputs();
|
||||||
@@ -91,17 +92,36 @@ void loop()
|
|||||||
//////// INIT SPI INTERFACES ////////
|
//////// INIT SPI INTERFACES ////////
|
||||||
bool spiA_ok = true;
|
bool spiA_ok = true;
|
||||||
bool spiB_ok = true;
|
bool spiB_ok = true;
|
||||||
|
//////// INIT SPI INTERFACES ////////
|
||||||
LOG_DEBUG("Init SPI Interfaces");
|
LOG_DEBUG("Init SPI Interfaces");
|
||||||
SPIClass SPI_A(FSPI);
|
SPIClass SPI_A(FSPI);
|
||||||
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
||||||
SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||||
LOG_DEBUG("Init SPI A ok");
|
LOG_DEBUG("Init SPI A ok");
|
||||||
#ifdef CH_B_ENABLE
|
Serial.readStringUntil('\n');
|
||||||
delay(50);
|
dev->m_spi_a.reset(&SPI_A);
|
||||||
|
dev->m_adc_a = std::make_unique<ADS1256>(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);
|
SPIClass SPI_B(HSPI);
|
||||||
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
||||||
SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||||
LOG_DEBUG("Init SPI B ok");
|
LOG_DEBUG("Init SPI B ok");
|
||||||
|
Serial.readStringUntil('\n');
|
||||||
|
dev->m_spi_b.reset(&SPI_B);
|
||||||
|
dev->m_adc_b = std::make_unique<ADS1256>(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
|
#endif
|
||||||
|
|
||||||
if (!spiA_ok || !spiB_ok)
|
if (!spiA_ok || !spiB_ok)
|
||||||
@@ -111,37 +131,23 @@ void loop()
|
|||||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
esp_restart();
|
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<ADS1256>(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<ADS1256>(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");
|
LOG_DEBUG("Init SPI OK");
|
||||||
|
Serial.readStringUntil('\n');
|
||||||
|
|
||||||
//////// INIT I2C INTERFACES ////////
|
//////// INIT I2C INTERFACES ////////
|
||||||
LOG_DEBUG("Init I2C Interfaces");
|
// LOG_DEBUG("Init I2C Interfaces");
|
||||||
bool i2c_ok = true;
|
// bool i2c_ok = true;
|
||||||
i2c_ok = Wire.begin(SDA, SCL, 100000);
|
// i2c_ok = Wire.begin(SDA, SCL, 100000);
|
||||||
if (!i2c_ok)
|
// if (!i2c_ok)
|
||||||
{
|
// {
|
||||||
LOG_ERROR("Unable to Initialize I2C Bus");
|
// LOG_ERROR("Unable to Initialize I2C Bus");
|
||||||
LOG_ERROR("5 seconds to restart...");
|
// LOG_ERROR("5 seconds to restart...");
|
||||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
// vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
esp_restart();
|
// esp_restart();
|
||||||
}
|
// }
|
||||||
|
// LOG_DEBUG("Init I2c ok");
|
||||||
|
// Serial.readStringUntil('\n');
|
||||||
|
|
||||||
// Init IO Expanders
|
// Init IO Expanders
|
||||||
// dev->m_ext_io = std::make_unique<ExternalIO>(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT);
|
// dev->m_ext_io = std::make_unique<ExternalIO>(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT);
|
||||||
@@ -212,7 +218,9 @@ void loop()
|
|||||||
//////// SPAWN REALTIME TASKS ////////
|
//////// SPAWN REALTIME TASKS ////////
|
||||||
auto task_A = rtIgnitionTask(taskA_params, PSRAM_MAX, QUEUE_MAX, CORE_0, fs_mutex);
|
auto task_A = rtIgnitionTask(taskA_params, PSRAM_MAX, QUEUE_MAX, CORE_0, fs_mutex);
|
||||||
delay(50);
|
delay(50);
|
||||||
|
Serial.readStringUntil('\n');
|
||||||
auto task_B = rtIgnitionTask(taskB_params, PSRAM_MAX, QUEUE_MAX, CORE_1, fs_mutex);
|
auto task_B = rtIgnitionTask(taskB_params, PSRAM_MAX, QUEUE_MAX, CORE_1, fs_mutex);
|
||||||
|
Serial.readStringUntil('\n');
|
||||||
|
|
||||||
// Ignition A on Core 0
|
// Ignition A on Core 0
|
||||||
auto ignA_task_success = task_A.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
|
auto ignA_task_success = task_A.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
|
||||||
|
|||||||
Reference in New Issue
Block a user