XIAO nrf52840 and I2S

Has anybody been able to get I2S working with the nrf52* XIAO?
Some issues:

  • only pins 4,5,6 seems to work consistently
  • audio output is terrible compared to similar setups

I am using a sparkfun I2S module.

Hmm, I was wondering that also , so I clicked your link and then compared it to the “rich interfaces” stated in the Xiao Nrf52840 Sense ?? I’m not seeing it?
you have code or a schematic your using??
IFAIK…
I love me some Flacc audio files. :slight_smile:

  • Rich interfaces: 1xUART, 1xI2C, 1xSPI, 1xNFC, 1xSWD, 11xGPIO(PWM), 6xADC

“The SparkFun I2S Audio Breakout board uses the MAX98357A digital to analog converter (DAC), which converts I2S (not be confused with I2C) audio to an analog signal to drive speakers. The I2S Audio Breakout converts the digital audio signals using the I2S standard to an analog signal and amplifies the signal using a class D amplifier which can deliver up to 3.2W of power into a 4Ω load. The board can be configured to output only the left channel audio, right channel, or both.”
HTH
GL :-p

edit: I see this in the Xiao esp32c3 but I believe it to be a misprint…
Seeed Studio XIAO ESP32C3 has rich interfaces.
There are 11 digital I/O that can be used as PWM pins and 4 analog inputs that can be used as ADC pins . It supports four serial communication interfaces such as UART, I2C, SPI and I2S . This wiki will be helpful to learn about these interfaces and implement them in your next projects! . ^^^^^^ nope.

On the nrf52840 I2S is supported in hardware. Or at least it should be, I haven’t been able to play an audio yet successfully.
It works but it sounds really poor.

Yes , I see where the peripheral is capable,


it’s part of the multiplexed pins , From what I gleaned its pin 0-4 and you write to the config registers to set it up and probably use the EasyDMA for smooth operation. May be better suited to the esp32c3 then and must NOT be a misprint but it is very cool if it does.
GL
:slight_smile:

Why do you mentions pin 0-4 as the only ones usable?
Where in the schematics is that constraint expressed?

Not sure now , I’ll try and locate it but I know the NRf52 example shows pins 0-4.
Also if you use the I2C interface and Serial port , That’s all that is left. I know it says any Gpio pin with-in the 22 mux-io’s but seed only brings out a handful , also
if it sounds bad I may be configured for Phillips TDM instead of PDM or PCM.
HTH
GL
:wink:

Map IO pins using the PINSEL registers
// MCK routed to pin 0
NRF_I2S->PSEL.MCK = (0 << I2S_PSEL_MCK_PIN_Pos) | 
                    (I2S_PSEL_MCK_CONNECT_Connected <<
                                                 I2S_PSEL_MCK_CONNECT_Pos);
// SCK routed to pin 1
NRF_I2S->PSEL.SCK = (1 << I2S_PSEL_SCK_PIN_Pos) | 
                    (I2S_PSEL_SCK_CONNECT_Connected <<
                                                 I2S_PSEL_SCK_CONNECT_Pos); 
// LRCK routed to pin 2
NRF_I2S->PSEL.LRCK = (2 << I2S_PSEL_LRCK_PIN_Pos) | 
                     (I2S_PSEL_LRCK_CONNECT_Connected <<
                                                 I2S_PSEL_LRCK_CONNECT_Pos); 
// SDOUT routed to pin 3
NRF_I2S->PSEL.SDOUT = (3 << I2S_PSEL_SDOUT_PIN_Pos) | 
                      (I2S_PSEL_SDOUT_CONNECT_Connected <<
                                                 I2S_PSEL_SDOUT_CONNECT_Pos);
// SDIN routed on pin 4
NRF_I2S->PSEL.SDIN = (4 << I2S_PSEL_SDIN_PIN_Pos) | 
                     (I2S_PSEL_SDIN_CONNECT_Connected <<
                                                 I2S_PSEL_SDIN_CONNECT_Pos); 

Old post too, can-a-xiao-be-configured-for-i2s
HTH
GL
:slight_smile:


also this pinout shows LRC,BCLK, DIN and is only aplicacable to I2S

1 Like

Thank you.
I found the solution.
The PIN numbers used in NRF_I2S->PSEL registers are not the Arduino Logical pins.
So if you want to use pin 7, 8, 9 for example, you have to translate into P1.12, P1.13, P1.14 (see picture below)
Which means translates to register values of: 32+12, 32+13, 32+14.


This is according to the NRF specs:

If I didn’t get any audio instead of degraded output, I would have caught this faster. :man_facepalming:

Awesome… It’s should sound great in the end.
Great topic too. :+1:

GL :slight_smile:

Put some code to do MP3 decoding and I2S playing here:

1 Like