And then you can use the DMA example found in the Zero I2S library:
File -> Examples -> Adafruit Zero I2S Library -> dma
#include <Adafruit_ZeroI2S.h>
#include <Adafruit_ZeroDMA.h>
#include "utility/dma.h"
#include <math.h>
/* max volume for 32 bit data */
#define VOLUME ( (1UL << 31) - 1)
/* create a buffer for both the left and right channel data */
#define BUFSIZE 256
int data[BUFSIZE];
Adafruit_ZeroDMA myDMA;
ZeroDMAstatus stat; // DMA status codes returned by some functions
Adafruit_ZeroI2S i2s;
void dma_callback(Adafruit_ZeroDMA *dma) {
/* we don't need to do anything here */
}
void setup()
{
Serial.begin(115200);
//while(!Serial); // Wait for Serial monitor before continuing
Serial.println("I2S output via DMA");
int *ptr = data;
/*the I2S module will be expecting data interleaved LRLR*/
for(int i=0; i<BUFSIZE/2; i++){
/* create a sine wave on the left channel */
*ptr++ = sin( (2*PI / (BUFSIZE/2) ) * i) * VOLUME;
/* create a cosine wave on the right channel */
*ptr++ = cos( (2*PI / (BUFSIZE/2) ) * i) * VOLUME;
© Adafruit Industries
https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a
Page 37 of 45