Adafruit Zero I2S library not working with RTCZero library

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jmacarthur
 
Posts: 9
Joined: Thu Dec 08, 2016 11:46 am

Adafruit Zero I2S library not working with RTCZero library

Post by jmacarthur »

Anyone else come across this? If you start with the "basic" example from the Adafruit Zero I2S library, and add RTC functionality, it breaks the I2S. You don't have to do anything more than rtc.begin, so I'm not sleeping the processor or anything. I'm using a stock MKRZero with Adafruit MAX98357A I2S amplifier. Code below. Comment out rtc.begin() and it works fine.


#include <Arduino.h>
#include <Adafruit_ZeroI2S.h>
#include <math.h>
#include <RTCZero.h>

// Copied from Adafruit I2S basic example, added RTC. rtc.begin() breaks I2S

/* max volume for 32 bit data */
#define VOLUME ( (1UL << 31) - 1)
#define MUTEPIN 5

/* create a buffer for both the left and right channel data */
#define BUFSIZE 128
int left[BUFSIZE];
int right[BUFSIZE];

/* Create an rtc object */

RTCZero rtc;

// Use default pins in board variant
Adafruit_ZeroI2S i2s = Adafruit_ZeroI2S();

void setup()
{
pinMode(MUTEPIN,OUTPUT); // MUTE
digitalWrite(MUTEPIN,HIGH); //start out unmuted

rtc.begin(); //fails until you comment it out


// while (!Serial) delay(10);

// Serial.println("I2S demo");

for(int i=0; i<BUFSIZE; i++){
/* create a sine wave on the left channel */
left = sin( (2*PI / (BUFSIZE) ) * i) * VOLUME;

/* create a cosine wave on the right channel */
right = cos( (2*PI / (BUFSIZE) ) * i) * VOLUME;
}

/* begin I2S on the default pins. 24 bit depth at
* 44100 samples per second
*/
i2s.begin(I2S_32_BIT, 44100);
i2s.enableTx();
}

void loop()
{
/* write the output buffers
* note that i2s.write() will block until both channels are written.
*/
for(int i=0; i<BUFSIZE; i++){
i2s.write(left, right);
}
}

User avatar
mikeysklar
 
Posts: 14165
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit Zero I2S library not working with RTCZero libra

Post by mikeysklar »

Yes, I believe this is an open issue.

https://github.com/arduino/ArduinoCore-samd/issues/451

"Incompatibility between MKRZERO RTC & I2S libraries #451"

User avatar
robertcarell
 
Posts: 6
Joined: Tue Aug 10, 2021 11:34 pm

Re: Adafruit Zero I2S library not working with RTCZero libra

Post by robertcarell »

yup, it happens a lot, when you are working on Arduino and using third party libraries, they don't get compatible with each other. Embedded Systems is not that easy.

You are having the same problem, so you have to use one of them.

Once I encountered a similar issue and I have to use a second Arduino board and then I sent data via serial port to the first Arduino.

User avatar
jmacarthur
 
Posts: 9
Joined: Thu Dec 08, 2016 11:46 am

Re: Adafruit Zero I2S library not working with RTCZero libra

Post by jmacarthur »

It appears that RTC.begin() is enabling register protection on a register that the I2S needs. The fix is to initialize the I2S before the RTC -- at least that worked for me.

User avatar
mikeysklar
 
Posts: 14165
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit Zero I2S library not working with RTCZero libra

Post by mikeysklar »

That is cool that you got it going by changing the init order.

Does the time hold and sound continue to work as long as I2S is initialized before RTC?

User avatar
jmacarthur
 
Posts: 9
Joined: Thu Dec 08, 2016 11:46 am

Re: Adafruit Zero I2S library not working with RTCZero libra

Post by jmacarthur »

Apparently. I'll mess around with it and let you know if there's any trouble.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”