1

Background

I have need for a data logging application running on a "Arduino compatible" chipKit UNO32 board, with a connected sensor. Data should be logged to an SD-card found on a "Arduino Wireless SD shield". The sensor is connected via I2C.

My problem is that when I use the Arduino SD library writing is slow: 25 ms per print() operation, which gives me a maximum of 40 Hz which is laughable compared to the 100-800Hz data rate of my sensor.

My faulty solution

Luckily the sensor comes equipped with both an on-chip FIFO that can store 32 sensor values. This means I can go to at least 200Hz without any troubles since the time to fill the FIFO is way larger than the time to write to the card. But I'd still really like to get to at least 400Hz, so I thought I'd have the following setup:

  1. Tell sensor to put data in the FIFO
  2. When the FIFO is almost full, the sensor triggers an interrupt (sensor does this, and it works, I can catch the interrupt)
  3. When the Arduino receives the interrupt, it polls the sensor for data (via I2C) and stores the data in a buffer in SRAM.
  4. When the SRAM buffer is getting full, write its contents to the SD-card.

Unfortunately, this does not seem to work since the Arduino Wire library that handles I2C use interrupts, and can not be called from within an interrupt handler. I have tried it, and it freezes the microcontroller.

My question

There seems to be other I2C libraries for Arduino that do not rely on interrupts. Should I try that route?

Or is my way of thinking (grabbing a load of data in an ISR) bad from start? Is there another approach I should take?

1 Answer 1

0

Just use the interrupt to set a flag and finish the ISR. from the main loop do the calling I2C instead of directly calling from ISR.

boolean fifoFull = false;

void fifoISR() {
    fifoFull = true;
}

void loop() {
    if(fifoFull) {
        // Do I2C
        fifoFull = false;
    }
}
2
  • The problem is that writing the SD card takes longer than filling the FIFO. That means collecting new data would have to have priority over writing to the SD card. Hence my wish to collect the new data in the ISR. Oct 25, 2012 at 14:47
  • ISR is not supposed to be used for processing intensive tasks. Because of the sporadic, a-periodic nature of Interrupts coming in.
    – shazin
    Oct 26, 2012 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.