I have a couple of A/D converters and am reading them every 100 µs over SPI, using the timer interrupt routine with SPI clocked at 16 MHz.
Additionally, I have five digital temperature sensors using the I²C bus in a timer interrupt routine executed every second. With a 100 kHz I²C bus and two bytes per temperature sensor, it takes almost 1 ms to read the temperature.
Obviously while reading temperature values I cannot use the SPI bus, missing almost 10 A/D readouts while I²C is active.
How can I use slow and fast peripherals and have timely readouts?
Thanks, these are all great answers!
I am actually using Teensy 3.2 development board and would be nice to have a solution with ready-to-use Arduino IDE libraries. There is a library for Teensy 3.2 for I2C communication with DMA.
I think that the simplest solution is to read A/D converters using 100 us timer interrupt and increment a variable inside the interrupt routine to initiate I2C communication in the main code every second (Microchip TC74 temperature sensors).
I have never used DMA before and my question is what happens when I2C bus is active (reading), and 100us timer interrupt comes. Will it be accepted right away or uC will wait until the byte readout is finished on I2C, or interrupt will be accepted and I2c reading will continue independently?