Go Down

Topic: I2S  (Read 182 times) previous topic - next topic

mjohansson95

Apr 24, 2019, 12:37 pm Last Edit: Apr 24, 2019, 01:44 pm by mjohansson95
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??


Code: [Select]
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**
}

Robin2

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

Please post a complete program.



When posting code please use the code button </>


Code: [Select]
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
Two or three hours spent thinking and reading documentation solves most programming problems.

mjohansson95

#2
Apr 24, 2019, 01:08 pm Last Edit: Apr 24, 2019, 01:45 pm by mjohansson95
No, I think I mean I2S.

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

Thanks anyway.

sherzaad

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

from github(https://github.com/arduino/ArduinoCore-samd/tree/master/libraries/I2S/src):

Code: [Select]
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;
}

mjohansson95


Robin2

#5
Apr 24, 2019, 03:17 pm Last Edit: Apr 24, 2019, 03:18 pm by Robin2
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
Two or three hours spent thinking and reading documentation solves most programming problems.

mjohansson95

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.

Robin2

You don't have to be so rude about it.
Apologies. I was feeling frustrated.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up