I'm working on a Arduino Uno and a ADC ADS1115. Devices communicate by I2C where Arduino is the master.
I would like to use the ADC to the maximum of his possibility.
So i configure the ADC to set a pin when a conversion finish and use this pin as an external interrupt. But i can't read the data because I2C interrupt can't work in a external interrupt handler. I think to use a timer to have a fixed sampling rate too, but it's the same issue.
There is my code below, and if you have any idea of how i can doing my goal let's share it ;)
#include <QueueArray.h>
#include <ADS1115_Vibratec.h>
Adafruit_ADS1115 ads;
QueueArray <uint16_t> fifo;
int i=0;
void setup() {
Wire.begin();
Serial.begin(115200);
ads.Config( ADS1115_REG_CONFIG_OS_NOEFFECT,
ADS1115_REG_CONFIG_MUX_DIFF_0_1,
ADS1115_REG_CONFIG_PGA_6_144V,
ADS1115_REG_CONFIG_MODE_CONTIN,
ADS1115_REG_CONFIG_DR_860SPS,
ADS1115_REG_CONFIG_CMODE_TRAD,
ADS1115_REG_CONFIG_CPOL_ACTVLOW,
ADS1115_REG_CONFIG_CLAT_NONLAT,
ADS1115_REG_CONFIG_CQUE_1CONV);
ads.Set_ConvReady_function();
attachInterrupt(0,interrupt,RISING); //INT0 -> pin 2, fonction interrupt, front montant
}
void loop() {
while (!fifo.isEmpty ())
{
Serial.write(fifo.dequeue());
Serial.println();
}
}
void interrupt()
{
fifo.enqueue(ads.ReadConvert());
}