Record to SD Card & I2C Command Issues

Ceiling

Member
Hey folks-

I have a project where I'm recording stereo audio to an SD card on the Audio shield with a Teensy 3.2. The sketch records and plays fine, but the recording is sped up/distorted if I run any commands on the I2C bus while it's recording. I have an OLED and a GPIO expander on the I2C bus as well as the Audio shield.

I initially had problems with SD card write times/missing samples when I first started the project, so I thought this may be something similar, however, I tried increasing the AudioMemory and didn't notice any difference. For reference I'm using a SanDisk 16gb SD card. The project is on a custom PCB, so there may be potential for noise as well (there's some wires from reworking the board). I don't necessarily have to be using the I2C bus while I'm recording and could likely could run the I2C commands on an event rather than in the loop, but I was curious because I thought in theory I should be able to do both I2S and I2C. Maybe recording to the SD card is further complicating things?

I'd appreciate any input.

Thanks!
 
I2C is relatively slow compared to modern processors. Adding to the issue is that the historical Arduino Wire library is somewhat brain dead in that it blocks during the end transaction function call while it writes all the data.

If you were using the Wire library at the default speed of 100k baud and were using a OLED library that uses a frame buffer( such that for a 128x64 OLED the entire screen would be sent for any change ), it would take 1024 * 9 bits / 100k which is 92 ms. In that time you would be behind approximately 30 audio buffers in your writes to the SD card. Using Wire at 400k baud would speed this up by a factor of 4.

( 9 bits instead of 8 bits accounts for the ACK bit of each I2C write )
 
Back
Top