cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting STM32L4 over I2S (SAI port) to external Audio Codec

Jal Panchal
Associate III

I have an analog mic connected at an Audio Codec (MAX98090) which provides an I2S connectivity.

I would like to connect this Codec over I2S to the STM32L4 . I have SensorTile and the Nucleo, both have the STM2L476 chip with 2 SAI ports to test the connections.

I can see that the SensorTile Cradle expansion has 4 SAI pins in the Arduino connector.

Could someone help me with the hardware connection and where I can find libraries and example codes to read the data on the computer over USB.

7 REPLIES 7

The L496 DISCO https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/32l496gdiscovery.html contains a SAI-connected CODEC, so you can get inspired there for the hardware connections, and in CubeL4 there sure are examples for this board too.

But if you want things ready made, why don't you simply buy a USB soundcard?

JW

Jal Panchal
Associate III

Hi,

I'll check the connections on this board. Thank you.

The MAX board and the STM32L4 are already part of a setup and I am trying to establish communication between them.

Jal Panchal
Associate III

I was able to make the connections. I am now trying to read the digital data on the computer..

I set up the SAI port and am using the following functions:

uint8_t data[256];

HAL_SAI_Receive(&hsai_BlockA2, data, SAI_DATASIZE_16, 100 );

 USBD_CDC_SetTxBuffer(&hUsbDeviceFS, data, sizeof(data));

 USBD_CDC_TransmitPacket(&hUsbDeviceFS);

and reading the digital data on the computer.

I am unable to decipher the I2S serial data. Can anyone guide me?

Observe the I2S clocks/data using a logic analyzer. If those data don't make sense, you might have incorrectly set up the codec through the I2C.

JW

I dont own a logic analyser. I tried plotting the registers using ST studio but didnt quite get the right data there either..

This doesn't sound very reassuring. If you are a student, I recommend you to see your teacher/tutor and discuss adequateness of your task. You may want to move to a platform which already has some software support you could rely on and build upon.

I2S CODECs usually require a steady clock, i.e. you don't simply transfer a block and then do something else. Usually you run the I2S (as implemented in SAI) continuously and feed/sink data through DMA in circular mode. You can then process that data in main.

And the CODECs are relatively complex machines, which usually have quite an extensive set of registers you would need to set through a different interface, here I2C. I am not going to study that particular CODEC of your choice whether it has a chance working without any setup - sometimes they do have a few hardware-strappable options.

JW

Although I don't have a Logic Analyser, I do have an oscilloscope and have tried plotting the I2S lines from the Audio Codec, which is on a development board of its own. I am pretty sure, its working right .

I have connected the 3 I2S pins (BCLK, WS, and SD) to the CN5 pins of the cradle expansion and I am trying read the SD line and plot the waveform.

I haven't explored the DMA that you are referring to. I did try using HAL_SAI_Receive_DMA but didn't get any data. I'll check this again and see if it helps.

I am surprised that STM @STM Community​ doesn't have exmaples to read audio. Most of the examples are for audio out.