Maxim Integrated's IoT development kit.
Dependencies: MAX30101 MAX30003 MAX113XX_Pixi MAX30205 max32630fthr USBDevice
Diff: main.cpp
- Revision:
- 10:dbeda3ffffb8
- Parent:
- 7:2c9c8b6a28a7
- Child:
- 11:04292fba5078
--- a/main.cpp Fri Apr 27 17:22:04 2018 +0300
+++ b/main.cpp Fri May 04 11:51:53 2018 +0300
@@ -178,13 +178,13 @@
void buttonPressedCallback(void)
{
- eventQueue.call(Callback<void(uint8_t)>(&updateButtonState), ++buttonPressedCount);
+ eventQueue.call(Callback<void(uint8_t)>(&updateButtonState), ++buttonPressedCount);
}
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
printf("disc\r\n");
- BLE::Instance().gap().startAdvertising(); // restart advertising
+ BLE::Instance().gap().startAdvertising(); // restart advertising
}
/* Connection */
@@ -200,7 +200,7 @@
void onBleInitError(BLE &ble, ble_error_t error)
{
- /* Initialization error handling should go here */
+ /* Initialization error handling should go here */
}
/**
@@ -212,49 +212,49 @@
void onDataWrittenCallback(const GattWriteCallbackParams *params)
{
if ((params->handle == gattCharRGBLed.getValueHandle()) && (params->len >= 3)) {
- rLED = (params->data[0] != 0) ? LED_OFF : LED_ON;
- gLED = (params->data[1] != 0) ? LED_OFF : LED_ON;
- bLED = (params->data[2] != 0) ? LED_OFF : LED_ON;
- }
+ rLED = (params->data[0] != 0) ? LED_OFF : LED_ON;
+ gLED = (params->data[1] != 0) ? LED_OFF : LED_ON;
+ bLED = (params->data[2] != 0) ? LED_OFF : LED_ON;
+ }
}
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
{
- BLE& ble = params->ble;
- ble_error_t error = params->error;
+ BLE& ble = params->ble;
+ ble_error_t error = params->error;
- if (error != BLE_ERROR_NONE) {
- /* In case of error, forward the error handling to onBleInitError */
- onBleInitError(ble, error);
- return;
- }
+ if (error != BLE_ERROR_NONE) {
+ /* In case of error, forward the error handling to onBleInitError */
+ onBleInitError(ble, error);
+ return;
+ }
- /* Ensure that it is the default instance of BLE */
- if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
- return;
- }
+ /* Ensure that it is the default instance of BLE */
+ if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
+ return;
+ }
- ble.gap().onDisconnection(disconnectionCallback);
- ble.gap().onConnection(connectionCallback);
+ ble.gap().onDisconnection(disconnectionCallback);
+ ble.gap().onConnection(connectionCallback);
- ble.gattServer().onDataWritten(onDataWrittenCallback);
+ ble.gattServer().onDataWritten(onDataWrittenCallback);
- ble.gattServer().addService(iotService);
+ ble.gattServer().addService(iotService);
- /* setup advertising */
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
- ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
- ble.gap().setAdvertisingInterval(1000); /* 1000ms. */
- ble.gap().startAdvertising();
+ /* setup advertising */
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+ ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+ ble.gap().setAdvertisingInterval(1000); /* 1000ms. */
+ ble.gap().startAdvertising();
- button.fall(buttonPressedCallback);
+ button.fall(buttonPressedCallback);
}
void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
- BLE &ble = BLE::Instance();
- eventQueue.call(Callback<void()>(&ble, &BLE::processEvents));
+ BLE &ble = BLE::Instance();
+ eventQueue.call(Callback<void()>(&ble, &BLE::processEvents));
}
/******************************************************************************
@@ -262,29 +262,27 @@
******************************************************************************/
#if defined(LIB_MAX30205)
-#define MAX30205_DATA_READ_PERIOD_MSEC 5000
-
MAX30205 max30205_temp_sensor(i2c1, 0x48); /* New MAX30205 on i2cBus */
Thread thread_max30205_reader;
bool max30205_config(MAX30205 &temp_sensor){
- int rc = 0;
+ int rc = 0;
- MAX30205::Configuration_u temp_cfg;
- temp_cfg.all = 0;
- temp_cfg.bits.shutdown = 1; // Shutdown mode
- temp_cfg.bits.comp_int = 1; // Interrupt mode
- temp_cfg.bits.os_polarity = 0; // Active low OS
- temp_cfg.bits.fault_queue = 1; // Two faults for OS condition
- temp_cfg.bits.data_format = 0; // Normal data format
- temp_cfg.bits.timeout = 0; // I2C timeout reset enabled
- temp_cfg.bits.one_shot = 0; // Start with one-shot = 0
+ MAX30205::Configuration_u temp_cfg;
+ temp_cfg.all = 0;
+ temp_cfg.bits.shutdown = 1; // Shutdown mode
+ temp_cfg.bits.comp_int = 1; // Interrupt mode
+ temp_cfg.bits.os_polarity = 0; // Active low OS
+ temp_cfg.bits.fault_queue = 1; // Two faults for OS condition
+ temp_cfg.bits.data_format = 0; // Normal data format
+ temp_cfg.bits.timeout = 0; // I2C timeout reset enabled
+ temp_cfg.bits.one_shot = 0; // Start with one-shot = 0
- rc = temp_sensor.writeConfiguration(temp_cfg); // Write config to MAX30205
+ rc = temp_sensor.writeConfiguration(temp_cfg); // Write config to MAX30205
- return rc;
+ return rc;
}
void max30205_reader_task()
@@ -334,17 +332,17 @@
#define MAX30101_IRQ_ASSERTED_ID 1
//variable for the algorithm
-uint16_t sampleRate =100;
-uint16_t compSpO2=1;
-int16_t ir_ac_comp =0;
-int16_t red_ac_comp=0;
-int16_t green_ac_comp=0;
-int16_t ir_ac_mag=0;
-int16_t red_ac_mag=0;
-int16_t green_ac_mag=0;
-uint16_t HRbpm2=0;
-uint16_t SpO2B=0;
-uint16_t DRdy=0;
+uint16_t sampleRate = 100;
+uint16_t compSpO2 = 1;
+int16_t ir_ac_comp = 0;
+int16_t red_ac_comp = 0;
+int16_t green_ac_comp = 0;
+int16_t ir_ac_mag = 0;
+int16_t red_ac_mag = 0;
+int16_t green_ac_mag = 0;
+uint16_t HRbpm2 = 0;
+uint16_t SpO2B = 0;
+uint16_t DRdy = 0;
//declare large variables outside of main
uint32_t redData[500];//set array to max fifo size
@@ -355,99 +353,95 @@
bool max30101_config(MAX30101 &op_sensor)
{
-
- //Reset Device
- MAX30101::ModeConfiguration_u modeConfig;
- modeConfig.all = 0;
- modeConfig.bits.reset = 1;
- modeConfig.bits.mode = MAX30101::MultiLedMode; // Sets SPO2 Mode
- int32_t rc = op_sensor.setModeConfiguration(modeConfig);
+ //Reset Device
+ MAX30101::ModeConfiguration_u modeConfig;
+ modeConfig.all = 0;
+ modeConfig.bits.reset = 1;
+ modeConfig.bits.mode = MAX30101::MultiLedMode; // Sets SPO2 Mode
+ int32_t rc = op_sensor.setModeConfiguration(modeConfig);
- //enable MAX30101 interrupts
- MAX30101::InterruptBitField_u ints;
- if(rc == 0) {
- ints.all = 0;
- ints.bits.a_full = 1; // Enable FIFO almost full interrupt
- ints.bits.ppg_rdy =1; //Enables an interrupt when a new sample is ready
- rc = op_sensor.enableInterrupts(ints);
- }
+ //enable MAX30101 interrupts
+ MAX30101::InterruptBitField_u ints;
+ if (rc == 0) {
+ ints.all = 0;
+ ints.bits.a_full = 1; // Enable FIFO almost full interrupt
+ ints.bits.ppg_rdy =1; //Enables an interrupt when a new sample is ready
+ rc = op_sensor.enableInterrupts(ints);
+ }
- //configure FIFO
- MAX30101::FIFO_Configuration_u fifoConfig;
- if(rc == 0) {
- fifoConfig.all = 0;
- fifoConfig.bits.fifo_a_full = 10; // Max level of 17 samples
- fifoConfig.bits.sample_average = MAX30101::AveragedSamples_0;// Average 0 samples
- rc = op_sensor.setFIFOConfiguration(fifoConfig);
- }
+ //configure FIFO
+ MAX30101::FIFO_Configuration_u fifoConfig;
+ if (rc == 0) {
+ fifoConfig.all = 0;
+ fifoConfig.bits.fifo_a_full = 10; // Max level of 17 samples
+ fifoConfig.bits.sample_average = MAX30101::AveragedSamples_0;// Average 0 samples
+ rc = op_sensor.setFIFOConfiguration(fifoConfig);
+ }
- MAX30101::SpO2Configuration_u spo2Config;
- if(rc == 0) {
- spo2Config.all = 0; // clears register
- spo2Config.bits.spo2_adc_range = 1; //sets resolution to 4096 nAfs
- spo2Config.bits.spo2_sr = MAX30101::SR_100_Hz; // SpO2 SR = 100Hz
- spo2Config.bits.led_pw = MAX30101::PW_3; // 18-bit ADC resolution ~400us
- rc = op_sensor.setSpO2Configuration(spo2Config);
- }
+ MAX30101::SpO2Configuration_u spo2Config;
+ if (rc == 0) {
+ spo2Config.all = 0; // clears register
+ spo2Config.bits.spo2_adc_range = 1; //sets resolution to 4096 nAfs
+ spo2Config.bits.spo2_sr = MAX30101::SR_100_Hz; // SpO2 SR = 100Hz
+ spo2Config.bits.led_pw = MAX30101::PW_3; // 18-bit ADC resolution ~400us
+ rc = op_sensor.setSpO2Configuration(spo2Config);
+ }
- //Set time slots for LEDS
- MAX30101::ModeControlReg_u multiLED;
- if (rc == 0) {
- //sets timing for control register 1
- multiLED.bits.lo_slot=1;
- multiLED.bits.hi_slot=2;
- rc = op_sensor.setMultiLEDModeControl(MAX30101::ModeControlReg1, multiLED);
- if (rc == 0) {
- multiLED.bits.lo_slot=3;
- multiLED.bits.hi_slot=0;
- rc = op_sensor.setMultiLEDModeControl(MAX30101::ModeControlReg2, multiLED);
- }
- }
+ //Set time slots for LEDS
+ MAX30101::ModeControlReg_u multiLED;
+ if (rc == 0) {
+ //sets timing for control register 1
+ multiLED.bits.lo_slot=1;
+ multiLED.bits.hi_slot=2;
+ rc = op_sensor.setMultiLEDModeControl(MAX30101::ModeControlReg1, multiLED);
+ if (rc == 0) {
+ multiLED.bits.lo_slot=3;
+ multiLED.bits.hi_slot=0;
+ rc = op_sensor.setMultiLEDModeControl(MAX30101::ModeControlReg2, multiLED);
+ }
+ }
- //Set LED drive currents
- if(rc == 0) {
- // Heart Rate only, 1 LED channel, Pulse amp. = ~7mA
- rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x24);
- //To include SPO2, 2 LED channel, Pulse amp. ~7mA
- if (rc == 0) {
- rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED2_PA, 0x24);
- }
- if (rc == 0) {
- rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED3_PA, 0x24);
- }
+ //Set LED drive currents
+ if (rc == 0) {
+ // Heart Rate only, 1 LED channel, Pulse amp. = ~7mA
+ rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x24);
+ //To include SPO2, 2 LED channel, Pulse amp. ~7mA
+ if (rc == 0) {
+ rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED2_PA, 0x24);
+ }
+ if (rc == 0) {
+ rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED3_PA, 0x24);
+ }
+ }
- }
+ //Set operating mode
+ modeConfig.all = 0;
+ if (rc == 0) {
+ modeConfig.bits.mode = MAX30101::MultiLedMode; // Sets multiLED mode
+ rc = op_sensor.setModeConfiguration(modeConfig);
+ }
- //Set operating mode
- modeConfig.all = 0;
- if(rc == 0) {
- modeConfig.bits.mode = MAX30101::MultiLedMode; // Sets multiLED mode
- rc = op_sensor.setModeConfiguration(modeConfig);
- }
-
-
- return rc;
+ return rc;
}
void max30101wing_pmic_config(I2C & i2c_bus, DigitalOut & pmic_en)
{
-
- const uint8_t PMIC_ADRS = 0x54;
- const uint8_t BBB_EXTRA_ADRS = 0x1C;
- const uint8_t BOOST_VOLTAGE = 0x05;
+ const uint8_t PMIC_ADRS = 0x54;
+ const uint8_t BBB_EXTRA_ADRS = 0x1C;
+ const uint8_t BOOST_VOLTAGE = 0x05;
- char data_buff[] = {BBB_EXTRA_ADRS, 0x40}; //BBBExtra register address
- //and data to enable passive
- //pull down.
- i2c_bus.write(PMIC_ADRS, data_buff,2); //write to BBBExtra register
+ char data_buff[] = {BBB_EXTRA_ADRS, 0x40}; //BBBExtra register address
+ //and data to enable passive
+ //pull down.
+ i2c_bus.write(PMIC_ADRS, data_buff,2); //write to BBBExtra register
- data_buff[0] = BOOST_VOLTAGE;
- data_buff[1] = 0x08; //Boost voltage configuration
- //register followed by data
- //to set voltage to 4.5V 1f
- pmic_en = 0; //disables VLED 08
- i2c_bus.write(PMIC_ADRS, data_buff,2); //write to BBBExtra register
- pmic_en = 1; //enables VLED
+ data_buff[0] = BOOST_VOLTAGE;
+ data_buff[1] = 0x08; //Boost voltage configuration
+ //register followed by data
+ //to set voltage to 4.5V 1f
+ pmic_en = 0; //disables VLED 08
+ i2c_bus.write(PMIC_ADRS, data_buff,2); //write to BBBExtra register
+ pmic_en = 1; //enables VLED
}
/* Op Sensor FIFO nearly full callback */
@@ -472,8 +466,6 @@
uint8_t fifoData[MAX30101::MAX_FIFO_BYTES];
uint16_t idx, readBytes;
- int32_t opSample;
- uint32_t sample;
uint16_t HRTemp;
uint16_t spo2Temp;
@@ -488,9 +480,9 @@
daplink.printf("Starting MAX30101 HeartRate / SPO2 Demo Application...\r\n");
daplink.printf("Please wait a few seconds while data is being collected.\r\n");
- Timer bleNotifyTimer;
+ Timer bleNotifyTimer;
- bleNotifyTimer.start();
+ bleNotifyTimer.start();
while (1) {
if (rc == 0) {
@@ -593,84 +585,81 @@
Thread thread_max30003_reader;
void ecg_config(MAX30003& ecgAFE) {
-
- // Reset ECG to clear registers
- ecgAFE.writeRegister( MAX30003::SW_RST , 0);
+ // Reset ECG to clear registers
+ ecgAFE.writeRegister( MAX30003::SW_RST , 0);
- // General config register setting
- MAX30003::GeneralConfiguration_u CNFG_GEN_r;
- CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
- CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
- CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
- CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
- CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
- CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
- ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);
+ // General config register setting
+ MAX30003::GeneralConfiguration_u CNFG_GEN_r;
+ CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
+ CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
+ CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
+ CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
+ CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
+ CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
+ ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);
- // ECG Config register setting
- MAX30003::ECGConfiguration_u CNFG_ECG_r;
- CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
- CNFG_ECG_r.bits.dhpf = 1; // Digital HPF cutoff = 0.5Hz
- CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V
- CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps
- ecgAFE.writeRegister( MAX30003::CNFG_ECG , CNFG_ECG_r.all);
+ // ECG Config register setting
+ MAX30003::ECGConfiguration_u CNFG_ECG_r;
+ CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
+ CNFG_ECG_r.bits.dhpf = 1; // Digital HPF cutoff = 0.5Hz
+ CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V
+ CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps
+ ecgAFE.writeRegister( MAX30003::CNFG_ECG , CNFG_ECG_r.all);
+
+
+ //R-to-R configuration
+ MAX30003::RtoR1Configuration_u CNFG_RTOR_r;
+ CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
+ ecgAFE.writeRegister( MAX30003::CNFG_RTOR1 , CNFG_RTOR_r.all);
- //R-to-R configuration
- MAX30003::RtoR1Configuration_u CNFG_RTOR_r;
- CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
- ecgAFE.writeRegister( MAX30003::CNFG_RTOR1 , CNFG_RTOR_r.all);
-
-
- //Manage interrupts register setting
- MAX30003::ManageInterrupts_u MNG_INT_r;
- MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples
- MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back
- ecgAFE.writeRegister( MAX30003::MNGR_INT , MNG_INT_r.all);
+ //Manage interrupts register setting
+ MAX30003::ManageInterrupts_u MNG_INT_r;
+ MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples
+ MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back
+ ecgAFE.writeRegister( MAX30003::MNGR_INT , MNG_INT_r.all);
- //Enable interrupts register setting
- MAX30003::EnableInterrupts_u EN_INT_r;
- EN_INT_r.all = 0;
- EN_INT_r.bits.en_eint = 1; // Enable EINT interrupt
- EN_INT_r.bits.en_rrint = 0; // Disable R-to-R interrupt
- EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
- ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all);
+ //Enable interrupts register setting
+ MAX30003::EnableInterrupts_u EN_INT_r;
+ EN_INT_r.all = 0;
+ EN_INT_r.bits.en_eint = 1; // Enable EINT interrupt
+ EN_INT_r.bits.en_rrint = 0; // Disable R-to-R interrupt
+ EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
+ ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all);
- //Dyanmic modes config
- MAX30003::ManageDynamicModes_u MNG_DYN_r;
- MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
- ecgAFE.writeRegister( MAX30003::MNGR_DYN , MNG_DYN_r.all);
+ //Dyanmic modes config
+ MAX30003::ManageDynamicModes_u MNG_DYN_r;
+ MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
+ ecgAFE.writeRegister( MAX30003::MNGR_DYN , MNG_DYN_r.all);
- // MUX Config
- MAX30003::MuxConfiguration_u CNFG_MUX_r;
- CNFG_MUX_r.bits.openn = 0; // Connect ECGN to AFE channel
- CNFG_MUX_r.bits.openp = 0; // Connect ECGP to AFE channel
- ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all);
+ // MUX Config
+ MAX30003::MuxConfiguration_u CNFG_MUX_r;
+ CNFG_MUX_r.bits.openn = 0; // Connect ECGN to AFE channel
+ CNFG_MUX_r.bits.openp = 0; // Connect ECGP to AFE channel
+ ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all);
- return;
+ return;
}
/* ECG FIFO nearly full callback */
-//volatile bool ecgFIFOIntFlag = 0;
void ecgFIFO_callback() {
-
thread_max30003_reader.signal_set(MAX30003_IRQ_ASSERTED_SIGNAL_ID);
- //ecgFIFOIntFlag = 1;
-
}
void max30003_reader_task()
{
// Constants
- const int EINT_STATUS_MASK = 1 << 23;
- const int FIFO_OVF_MASK = 0x7;
- const int FIFO_VALID_SAMPLE_MASK = 0x0;
- const int FIFO_FAST_SAMPLE_MASK = 0x1;
+ const int EINT_STATUS_MASK = 1 << 23;
+ const int FIFO_OVF_MASK = 0x7;
+ const int FIFO_VALID_SAMPLE_MASK = 0x0;
+ const int FIFO_FAST_SAMPLE_MASK = 0x1;
const int ETAG_BITS_MASK = 0x7;
+ uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
+
InterruptIn ecgFIFO_int(P5_4); // Config P5_4 as int. in for the
ecgFIFO_int.fall(&ecgFIFO_callback); // ecg FIFO almost full interrupt
@@ -680,12 +669,8 @@
MAX30003 ecgAFE(spiBus, P5_3); // New MAX30003 on spiBus, CS = P5_3
ecg_config(ecgAFE); // Config ECG
-
ecgAFE.writeRegister( MAX30003::SYNCH , 0);
- uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
- int16_t ecgSample[32];
-
daplink.printf("Starting MAX30003 ECG Demo Application...\r\n");
while (1) {
@@ -702,7 +687,6 @@
do {
ecgFIFO = ecgAFE.readRegister( MAX30003::ECG_FIFO ); // Read FIFO
- ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data
ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG
readECGSamples++; // Increment sample counter
@@ -748,94 +732,93 @@
void ecg_config(MAX30003& ecgAFE)
{
- // Reset ECG to clear registers
- ecgAFE.writeRegister( MAX30003::SW_RST , 0);
+ // Reset ECG to clear registers
+ ecgAFE.writeRegister( MAX30003::SW_RST , 0);
- // General config register setting
- MAX30003::GeneralConfiguration_u CNFG_GEN_r;
- CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
- CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
- CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
- CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
- CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
- CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
- ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);
+ // General config register setting
+ MAX30003::GeneralConfiguration_u CNFG_GEN_r;
+ CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
+ CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
+ CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
+ CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
+ CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
+ CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
+ ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);
- // ECG Config register setting
- MAX30003::ECGConfiguration_u CNFG_ECG_r;
- CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
- CNFG_ECG_r.bits.dhpf = 1; // Digital HPF cutoff = 0.5Hz
- CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V
- CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps
- ecgAFE.writeRegister( MAX30003::CNFG_ECG , CNFG_ECG_r.all);
+ // ECG Config register setting
+ MAX30003::ECGConfiguration_u CNFG_ECG_r;
+ CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
+ CNFG_ECG_r.bits.dhpf = 1; // Digital HPF cutoff = 0.5Hz
+ CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V
+ CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps
+ ecgAFE.writeRegister( MAX30003::CNFG_ECG , CNFG_ECG_r.all);
- //R-to-R configuration
- MAX30003::RtoR1Configuration_u CNFG_RTOR_r;
- CNFG_RTOR_r.bits.wndw = 0b0011; // WNDW = 96ms
- CNFG_RTOR_r.bits.rgain = 0b1111; // Auto-scale gain
- CNFG_RTOR_r.bits.pavg = 0b11; // 16-average
- CNFG_RTOR_r.bits.ptsf = 0b0011; // PTSF = 4/16
- CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
- ecgAFE.writeRegister( MAX30003::CNFG_RTOR1 , CNFG_RTOR_r.all);
+ //R-to-R configuration
+ MAX30003::RtoR1Configuration_u CNFG_RTOR_r;
+ CNFG_RTOR_r.bits.wndw = 0b0011; // WNDW = 96ms
+ CNFG_RTOR_r.bits.rgain = 0b1111; // Auto-scale gain
+ CNFG_RTOR_r.bits.pavg = 0b11; // 16-average
+ CNFG_RTOR_r.bits.ptsf = 0b0011; // PTSF = 4/16
+ CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
+ ecgAFE.writeRegister( MAX30003::CNFG_RTOR1 , CNFG_RTOR_r.all);
- //Manage interrupts register setting
- MAX30003::ManageInterrupts_u MNG_INT_r;
- MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples
- MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back
- ecgAFE.writeRegister( MAX30003::MNGR_INT , MNG_INT_r.all);
+ //Manage interrupts register setting
+ MAX30003::ManageInterrupts_u MNG_INT_r;
+ MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples
+ MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back
+ ecgAFE.writeRegister( MAX30003::MNGR_INT , MNG_INT_r.all);
- //Enable interrupts register setting
- MAX30003::EnableInterrupts_u EN_INT_r;
- EN_INT_r.bits.en_eint = 1; // Enable EINT interrupt
- EN_INT_r.bits.en_rrint = 1; // Enable R-to-R interrupt
- EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
- ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all);
+ //Enable interrupts register setting
+ MAX30003::EnableInterrupts_u EN_INT_r;
+ EN_INT_r.bits.en_eint = 1; // Enable EINT interrupt
+ EN_INT_r.bits.en_rrint = 1; // Enable R-to-R interrupt
+ EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
+ ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all);
- //Dyanmic modes config
- MAX30003::ManageDynamicModes_u MNG_DYN_r;
- MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
- ecgAFE.writeRegister( MAX30003::MNGR_DYN , MNG_DYN_r.all);
+ //Dyanmic modes config
+ MAX30003::ManageDynamicModes_u MNG_DYN_r;
+ MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
+ ecgAFE.writeRegister( MAX30003::MNGR_DYN , MNG_DYN_r.all);
- // MUX Config
- MAX30003::MuxConfiguration_u CNFG_MUX_r;
- CNFG_MUX_r.bits.openn = 0; // Connect ECGN to AFE channel
- CNFG_MUX_r.bits.openp = 0; // Connect ECGP to AFE channel
- ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all);
+ // MUX Config
+ MAX30003::MuxConfiguration_u CNFG_MUX_r;
+ CNFG_MUX_r.bits.openn = 0; // Connect ECGN to AFE channel
+ CNFG_MUX_r.bits.openp = 0; // Connect ECGP to AFE channel
+ ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all);
- return;
+ return;
}
void max30003_reader_task()
{
- // Constants
- const int EINT_STATUS = 1 << 23;
- const int RTOR_STATUS = 1 << 10;
- const int RTOR_REG_OFFSET = 10;
- const float RTOR_LSB_RES = 0.0078125f;
- const int FIFO_OVF = 0x7;
- const int FIFO_VALID_SAMPLE = 0x0;
- const int FIFO_FAST_SAMPLE = 0x1;
- const int ETAG_BITS = 0x7;
+ // Constants
+ const int EINT_STATUS = 1 << 23;
+ const int RTOR_STATUS = 1 << 10;
+ const int RTOR_REG_OFFSET = 10;
+ const float RTOR_LSB_RES = 0.0078125f;
+ const int FIFO_OVF = 0x7;
+ const int FIFO_VALID_SAMPLE = 0x0;
+ const int FIFO_FAST_SAMPLE = 0x1;
+ const int ETAG_BITS = 0x7;
- InterruptIn ecgFIFO_int(P5_4); // Config P5_4 as int. in for the
- ecgFIFO_int.fall(&ecgFIFO_callback); // ecg FIFO almost full interrupt
+ uint32_t ecgFIFO, RtoR, readECGSamples, ETAG[32], status;
+ float BPM;
+ Timer bleNotifyTimer;
- ecg_config(max30003); // Config ECG
-
- max30003.writeRegister( MAX30003::SYNCH , 0);
+ InterruptIn ecgFIFO_int(P5_4); // Config P5_4 as int. in for the
+ ecgFIFO_int.fall(&ecgFIFO_callback); // ecg FIFO almost full interrupt
- uint32_t ecgFIFO, RtoR, readECGSamples, idx, ETAG[32], status;
- int16_t ecgSample[32];
- float BPM;
- Timer bleNotifyTimer;
+ ecg_config(max30003); // Config ECG
- bleNotifyTimer.start();
- while (1) {
+ max30003.writeRegister( MAX30003::SYNCH , 0);
+
+ bleNotifyTimer.start();
+ while (1) {
// Read back ECG samples from the FIFO
thread_max30003_reader.signal_wait(MAX30003_IRQ_ASSERTED_SIGNAL_ID);
@@ -843,7 +826,7 @@
/* Read back ECG samples from the FIFO */
status = max30003.readRegister( MAX30003::STATUS ); // Read the STATUS register
- if (status & (RTOR_STATUS | EINT_STATUS) == 0) {
+ if ((status & (RTOR_STATUS | EINT_STATUS)) == 0) {
break;
}
@@ -872,7 +855,6 @@
do {
ecgFIFO = max30003.readRegister( MAX30003::ECG_FIFO ); // Read FIFO
- ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data
ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS; // Isolate ETAG
readECGSamples++; // Increment sample counter
@@ -905,26 +887,26 @@
void max11301_reader_task()
{
- uint16_t adcData;
- float adcVoltage;
+ uint16_t adcData;
+ float adcVoltage;
- MAX113XX_I2C pixi(i2c1, MAX113XX_I2C::MAX11301, MAX113XX_I2C_ADDRESS, P5_5);
+ MAX113XX_I2C pixi(i2c1, MAX113XX_I2C::MAX11301, MAX113XX_I2C_ADDRESS, P5_5);
- pixi.dacWrite(MAX113XX_Pixi::PORT0, 0x000); // Pixi PORT0 is -5V
- pixi.dacWrite(MAX113XX_Pixi::PORT1, 0xFFF); // Pixi PORT1 is +5V
+ pixi.dacWrite(MAX113XX_Pixi::PORT0, 0x000); // Pixi PORT0 is -5V
+ pixi.dacWrite(MAX113XX_Pixi::PORT1, 0xFFF); // Pixi PORT1 is +5V
- daplink.printf("Starting MAX11301 PIXI ADC Demo Application...\r\n");
+ daplink.printf("Starting MAX11301 PIXI ADC Demo Application...\r\n");
- while (1) {
- pixi.singleEndedADCRead(MAX113XX_Pixi::PORT9, adcData); // Read value from PORT9
- adcVoltage = -5 + 2.442e-3 * adcData; // Convert ADC val. to a voltage
+ while (1) {
+ pixi.singleEndedADCRead(MAX113XX_Pixi::PORT9, adcData); // Read value from PORT9
+ adcVoltage = -5 + 2.442e-3 * adcData; // Convert ADC val. to a voltage
- daplink.printf("ADC Read is : %i,\tVoltage is %1.3f V \r\n", adcData, adcVoltage);
+ daplink.printf("ADC Read is : %i,\tVoltage is %1.3f V \r\n", adcData, adcVoltage);
- bleGattAttrWrite(gattCharADC.getValueHandle(), (uint8_t *)&adcVoltage, sizeof(adcVoltage));
+ bleGattAttrWrite(gattCharADC.getValueHandle(), (uint8_t *)&adcVoltage, sizeof(adcVoltage));
- Thread::wait(MAX113XX_PIXI_BLE_NOTIFY_PERIOD_SEC * 1000);
- }
+ Thread::wait(MAX113XX_PIXI_BLE_NOTIFY_PERIOD_SEC * 1000);
+ }
}
#endif
@@ -939,7 +921,7 @@
aliveLedEventId = eventQueue.call_every(1000, blinkCallback);
- daplink.printf("Initializing BLE service...\r\n");
+ daplink.printf("Initializing BLE service...\r\n");
BLE &ble = BLE::Instance();
ble.onEventsToProcess(scheduleBleEventsProcessing);