2014-04-24 01:15 PM
I am having trouble using I2S to connect an audio codec, CS42L55, to the STM32F405. When I configure the STM32F4 to be in MasterTX mode, the codec reports that there is a clock ratio error. With an oscilloscope, I measure my MCLK signal at 12MHz and the LRCK measures at 48kHz, and I believe I have set the codec accordingly to give me a ratio of 250. I receive no output from the codec on the SDOUT line, and I see 32 clock changes on the SCK line between LRCK changes.
When I configure the STM32F4 in SlaveTX mode, I create a MCLK signal for the codec using a timer and measure the clock signal at 6MHz. The codec then creates and sends the LRCK and SCK signals. I measure LRCK at 48kHz and this time I only count 31 clock changes on the SCK line between LRCK changes. This time I am able to receive output on SDOUT and send output that I can hear on SDIN, but since I am missing that one clock tick on SCK the data I get from SDOUT is distorted -- it seems to be shifting circularly as more data comes in. The STM32F4 reports a frame error, which seems to make sense.The CS42L55 codec has a fixed output from the ADCs of 24bits and has a variable input which I am sending 24bits.Has anyone ever experienced something similar or have ideas on how to fix this? I have attached my configuration code with both my master and my slave configurations. Let me know if you need more of my code. #stm32f4-i2s-frame-cs42l55-codec2014-04-25 04:21 AM
Thread with similar problem here:
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F407%2C%20I2S%20with%208bit%20data%20format&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tview... I believe the I2S implementation in STM32 is not flexible enough to provide either a non-256-ratio between MCLK and LRCK/WS/sampling in master mode, or a non-16-or-32-bit frame in slave mode. The latter violates the I2S standard, but many chips out there - masters or slaves, transmitters or receivers - do so. OTOH, the said codec is a really weird piece of hardware. I hate software which decides configuration for me- and I wouldn't touch hardware which does the same with a stick. So, if you are not happy with the reconstruct-data-manually-in-software-and-ignore-framing-error solution (where codec is master), the only other option (besides external glue logic) is IMO to use timer(s) to generate clock waveforms to suit both the STM/I2S's and codec's quirks, and feed it to both in slave mode. Note, that as 250 does not divide by 32 evenly, you would need to vary the bit width (might be a case for DMA-fed TIMx_ARR or such). I personally would step back and select a more sane codec first. JW2014-04-25 10:27 AM
Thanks for the help. I was afraid that was the case.
I agree that the best solution is to pick out another codec, but I am apparently pretty bad/unlucky at that. Do you have any recommendations on a similar codec that would work with the STM32F4? Or what should I be looking for so I don't make the same mistake?