cancel
Showing results for 
Search instead for 
Did you mean: 

SAI configuration of the STM32L5xxx board

DYann.1
Senior II

Hello,

I would like to know if there are people who have already configured the SAI PORT to communicate with a CODEC ?

I configured like this :

DYann1_0-1690208469198.png

But I don't have the clock on the PIN PF7 :

DYann1_1-1690208589059.png

The SAI_MCLK_B is the curve in blue. Thank you for your helps.
Regards.

1 ACCEPTED SOLUTION

Accepted Solutions

clock...dont know. but without continuous stream anyway useless...the dac will not work.

so use dma channel ->

AScha3_0-1690212903496.png

enable callbacks in project-> advanced settings

AScha3_1-1690213024480.png

in main : register callbacks

AScha3_2-1690213148395.png

AScha3_4-1690213237338.png

then start it

AScha3_5-1690213285406.png

init buffer, size should match, what you expect in update interval; i use 32bit data ymmv.

int32_t playbuf[4096*2] __attribute__ ((aligned (32)));

and for begin, switch off d-cache, if your cpu has it. (cache management ...for later. :) )

in callbacks put your data, or for "pause" , set data zero. but never stop the running stream !

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

18 REPLIES 18
AScha.3
Chief III

yes, SAI to ES9038 DAC . working fine.

but...you just enabled the sai. doing nothing....

you see signal (and clock) when you send something !

typical I2S is continuous stream, so circular DMA -> SAI -> DAC (codec)

If you feel a post has answered your question, please click "Accept as Solution".

Hello,

I'm working SAI with another CODEC (SGTL5000) but the principle is the same for the SAI. First, I sent data to configure the CODEC via the I2C bus, that you can see in my previous screenshot (the yellow curve) but I haven't nothing on the PIN 'SAI_MCLK_B'. 

DYann1_0-1690209978327.png

I don't know if it is necessary to work in interruption, after your answer I have to work in DMA but how ?

DYann1_1-1690210154559.png

How to configure the settings? Do we leave it as default ?

DYann1_2-1690210363361.png

why in mode without DMA we do not see the clock ?

DYann.1
Senior II

I tried with this configuration but there are too many errors in this code

DYann1_3-1690211063440.png

24 errors

DYann1_4-1690211102968.png

Now I have no more errors these are priorities

clock...dont know. but without continuous stream anyway useless...the dac will not work.

so use dma channel ->

AScha3_0-1690212903496.png

enable callbacks in project-> advanced settings

AScha3_1-1690213024480.png

in main : register callbacks

AScha3_2-1690213148395.png

AScha3_4-1690213237338.png

then start it

AScha3_5-1690213285406.png

init buffer, size should match, what you expect in update interval; i use 32bit data ymmv.

int32_t playbuf[4096*2] __attribute__ ((aligned (32)));

and for begin, switch off d-cache, if your cpu has it. (cache management ...for later. :) )

in callbacks put your data, or for "pause" , set data zero. but never stop the running stream !

 

If you feel a post has answered your question, please click "Accept as Solution".

Guys, please stop posting code as images. Not only it makes reading harder, but the main harm is that images are not searchable neither with Ctrl+F, nor forum search, nor they are indexed by internet search engines. The forum has an "Insert/Edit code sample" button, which formats code properly.

Hi AScha.3,

Thank you for this helps. But I can't find the functions you mentioned : DYann1_0-1690268687365.png

How did you call these functions ? And I assume you put in the 'user code' in the Main ? Right ?

 

HAL_SAI_RegisterCallback (&hsai_BlockA1, HAL_SAI_TX_HALFCOMPLETE_CB_ID, HAL_SAI_TxHalfCpltCallback);
HAL_SAI_RegisterCallback (hsai_BlockA1, HAL_SAI_TX_COMPLETE_CB_ID, HAL_SAI_TxCpltCallback); 

fresult = HAL_DMA_Init (&hdma sai1a); 

 

but I think we're going too far and that doesn't answer my original question. Before communicating with the CODEC, I configured the CODEC in an operating mode (I2C) and I don't have NACK (an error in the I2C bus) and I think by what I don't have the MCLK clock that's why I asked for the easiest possible way to have the MCLK in order to be able to configure the CODEC. I hope I expressed myself well.

Thank you

yes.

(your snippet missing an "&" operator ! )

 

 

HAL_SAI_RegisterCallback(&hsai_BlockA1, HAL_SAI_TX_HALFCOMPLETE_CB_ID, HAL_SAI_TxHalfCpltCallback); 
HAL_SAI_RegisterCallback(&hsai_BlockA1, HAL_SAI_TX_COMPLETE_CB_ID, HAL_SAI_TxCpltCallback);

 

+you enabled sai callbacks in Cube (see my pic from cube) ?

+ whether your codec works with I2C without mclk - dont know. but running I2S continuous you need anyway.

so get the SAI running with DMA.

If you feel a post has answered your question, please click "Accept as Solution".

I have 2  errors with the first line

DYann1_0-1690270301893.png

 

the compiler tries to tell you: i use SAI block A , but you block B . so write ..blockB1 there !  :)

If you feel a post has answered your question, please click "Accept as Solution".