I2S

Hi there,

I'm trying to get my Arduino MKR WiFi 1010 to receive data from a 2 channel 24 bit ADC. The ADC communicates with I2S and the MKR WiFi is I2S compatible. The frequrency has to be very accurate, so an external clock from a timing module handles the ADC to run at 48 kHz. Now to my question. How does the I2S.read() work??

I2S.begin(I2S_PHILIPS_MODE, 24); 
int sample = 0;
char data[3]; 



void myInterrupt(){               //Triggered by the external clock?? 
   sample = I2S.read();           //How can this read a whole integer?? 
   data[0]=(sample & 0xff);
   data[1]=(sample>>8 & 0xff);
   data[2]=(sample>>16 & 0xff); 

   **The data is then sent through WiFi to another unit**
}

Are you sure you don't mean I2C rather than I2S?

Please post a complete program.

When posting code please use the code button </>
codeButton.png

so your code looks like this

and is easy to copy to a text editor See How to use the Forum

Also please use the AutoFormat tool to indent your code for easier reading.

...R

No, I think I mean I2S.

Thanks anyway.

mjohansson95:
...How does the I2S.read() work??

from github(ArduinoCore-samd/libraries/I2S/src at master · arduino/ArduinoCore-samd · GitHub):

int I2SClass::read(void* buffer, size_t size)
{
  if (_state != I2S_STATE_RECEIVER) {
    enableReceiver();
  }

  uint8_t enableInterrupts = ((__get_PRIMASK() & 0x1) == 0);

  // disable interrupts,
  __disable_irq();

  int read = _doubleBuffer.read(buffer, size);

  if (_dmaTransferInProgress == false && _doubleBuffer.available() == 0) {
    // no DMA transfer in progress, start a receive process
    _dmaTransferInProgress = true;

    DMA.transfer(_dmaChannel, i2sd.data(_deviceIndex), _doubleBuffer.data(), _doubleBuffer.availableForWrite());

    // switch to the next buffer for user output (will be empty)
    _doubleBuffer.swap();
  }

  if (enableInterrupts) {
    // re-enable the interrupts
    __enable_irq();
  }

  return read;
}

Thank you!!

mjohansson95:
No, I think I mean I2S.

http://www.arduino.cc/en/Reference/I2S

There is a separate section of the Forum for MKR Boards where I don't go so I would not have wasted my time with a silly question and you would not have had to waste your time answering it.

I am suggesting to the Moderator to move your Thread to that section.

...R

Robin2:
There is a separate section of the Forum for MKR Boards where I don't go so I would not have wasted my time with a silly question and you would not have had to waste your time answering it.

I am suggesting to the Moderator to move your Thread to that section.

...R

Well, since I2S is not only for the MKR boards I didn't want to limit my answers. You don't have to be so rude about it.

mjohansson95:
You don't have to be so rude about it.

Apologies. I was feeling frustrated.

...R