I2S in polling blocking mode STM32F4 Discovery Board, underrun but correct data on the logic analyser
Dear All,
It is my first message here, so I would say hello to everyone.
I'm trying to send some audio signal through I2S bus on the discovery board using the onboard CS43L22 audio codec. I've configured the codec using I2C and I2S on SPI3 peripheral.
I want to attempt to use polling, just as a first step before use interrupts and then use DMA. As I thought it would be good learning exercise.
I tried to play a sine wave but the signal is horribly loud and distorted, so I had a step back and I'm trying to generate just to different numerical values to right and left channels. I'm using the standard Phillips I2S mode and most of the settings are left as default (such as 16bit length etc.)
I think it underruns as it if I set a breakpoint when I check for underruns it stops there.
So I would've thought that I would need to use interrupts and DMA because maybe CPU can't handle that, but what puzzles me that the message is decoded correctly in a logic analyser.
Below is my main while loop:
while (1)
{
while(!((SPI3->SR&SPI_SR_TXE)&&((SPI3->SR&SPI_SR_CHSIDE)==0)))
{}
//write left channel
SPI3->DR=0xabcd;
//for right channel:
while(!((SPI3->SR&SPI_SR_TXE)&&(SPI3->SR&SPI_SR_CHSIDE)))
{}
SPI3->DR=0xffff;
i++;
if(i==number_of_samples)
i=0;
if((SPI3->SR&SPI_SR_OVR))
{
//breakpoint
}
if((SPI3->SR&SPI_SR_UDR))
{
//breakpoint, it stops here during debugging
}
}
Thank you in advance for any clues.
Many thanks,
Piotr Golacki
