Hi everyone!
I'm trying to understand how to use the I2S feature of STM32 cores, in particular, on the STM32F303RE and a low-cost CS4344-based dac board (this one
eBay auction: #174915064977 ).
My first goal is to play a sine wave through I2S fed by the DMA channel.
Here, in the attachment, are the configurations for the I2S module and the DMA
And here, is my code
/* USER CODE BEGIN 2 */
HAL_I2S_Init(&hi2s2);
HAL_I2S_Transmit_DMA(&hi2s2, (uint16_t*)sine2496, 512);
/* USER CODE END 2 */
/* USER CODE BEGIN 0 */
void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s)
{
HAL_I2S_Transmit_DMA(&hi2s2, (uint16_t*)sine2496, 512);
}
/* USER CODE END 0 */
const uint16_t sine2496[] = {
16383,
16383,
16785,
16785,
17187,
17187,
....
The samples of the sine table (despite its name it's a 16bits/48kHz sampling rate computed table) are duplicated to have the same signal on both stereo channels.
But the sound at the output is not a sine wave. Fortunately, I have a logical analyzer and I sampled that :
Marker 4: Frame one (see the table above) expected value on both channels
Marker 6: Unexpected values. I expected 16785 on the left and right channels.
Marker 7: Correct values but wrong place (expected at marker 6)
Marker 8: Unexpected values. I expected 17187 on the left and right channels.
Marker 9: Correct values but wrong place (expected at marker 8 )
etc
I don't understand why I have these unexpected values instead of the correct values.
The I2S signal frequency seems ok, I just need to check the MCLK with an oscilloscope because of the measured min/max/mean frequencies on the screenshot.
Do you have any ideas?
Thank you