2023-07-24 07:27 AM
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 :
But I don't have the clock on the PIN PF7 :
The SAI_MCLK_B is the curve in blue. Thank you for your helps.
Regards.
Solved! Go to Solution.
2023-07-24 08:45 AM - edited 2023-07-24 08:50 AM
clock...dont know. but without continuous stream anyway useless...the dac will not work.
so use dma channel ->
enable callbacks in project-> advanced settings
in main : register callbacks
then start it
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 !
2023-07-24 07:39 AM
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)
2023-07-24 07:50 AM - edited 2023-07-24 07:54 AM
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'.
I don't know if it is necessary to work in interruption, after your answer I have to work in DMA but how ?
How to configure the settings? Do we leave it as default ?
why in mode without DMA we do not see the clock ?
2023-07-24 08:05 AM - edited 2023-07-24 08:15 AM
I tried with this configuration but there are too many errors in this code
24 errors
Now I have no more errors these are priorities
2023-07-24 08:45 AM - edited 2023-07-24 08:50 AM
clock...dont know. but without continuous stream anyway useless...the dac will not work.
so use dma channel ->
enable callbacks in project-> advanced settings
in main : register callbacks
then start it
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 !
2023-07-24 02:58 PM
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.
2023-07-25 12:13 AM - edited 2023-07-25 12:15 AM
Hi AScha.3,
Thank you for this helps. But I can't find the functions you mentioned :
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
2023-07-25 12:26 AM - edited 2023-07-25 12:31 AM
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.
2023-07-25 12:31 AM
I have 2 errors with the first line
2023-07-25 12:35 AM
the compiler tries to tell you: i use SAI block A , but you block B . so write ..blockB1 there ! :)