2016-11-20 08:52 AM
Dear all,
I have a issue with SPDIF_TX on a nucleo F746ZG. Working on this since some days and can't identify the problem. I have some hearable ''glitches'' in an otherway working operation. A frequency sweep signal allows to reproduce those glitches on a regular basis. I recorded the output of the DAC/Amp and you can see in the attachment the visualization of the glitches: 4 ms amplitude ''dents'' in the signal. The 3 files attached allow to precisely visualize the issue. Please have a look. What is odd is that there is still the expected signal oscillation, but the amplitude is reduced for about 4ms or what looks like of multiple of 4 ms.
The upper part of the dataflow that prepares the data for the SAI has been well tested on a stm32F4 Discovery with I2S and onboard DAC without showing such a behaviour.
I prepare a buffer that is read by DMA (circular mode) to feed the SAI configured for SPDIF protocol. As SPDIF data are fixed in Stm32 to 24 bits for SPDIF, I prepare a buffer of int32 that I fill with int16 shifted by 8 bits (<<8). I alternate Left and Right music samples.
I noticed that I don't have the same result in the 3 below cases:
- 0 for Left channel and music for Right: music and glitches in Right channel, silence on left channel
- music (same data) in Left and Right channels: glitches in Left and right channels,
- strange: - Music for Left channel and 0 for Right: music and NO glitches in Left channel, silence on right channel !!!!
So feeding the SAI with comparable data does not give the same result: 0=>L/Music=>R different from 0=>R/Music=>L
I have tried to play with:
- length of the buffer: no effect,
- amplitude of the signal: no effect,
- frequency: the pure frequency signals that I tried doesn't seems to exhibit the glitches...
- and the signal that continues to oscillate during the glitch, with a suddenly wrong amplitude.
Problem of DMA configuration?
Problem of SAI configuration?
Note: I have to set the
hsai_BlockB1.
Init
.
AudioFrequency
= SAI_AUDIO_FREQUENCY_96K to efectively have 48k recognized by my DAC. With this setting, I can play music at the right pace.
DMA is set to work with WORDS (I believe) as:
hdma_sai1_a.Instance = DMA2_Stream1;
hdma_sai1_a.Init.Channel = DMA_CHANNEL_0;
hdma_sai1_a.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_sai1_a.Init.PeriphInc = DMA_PINC_DISABLE; hdma_sai1_a.Init.MemInc = DMA_MINC_ENABLE;
hdma_sai1_a.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_sai1_a.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_sai1_a.Init.Mode = DMA_CIRCULAR;
hdma_sai1_a.Init.Priority = DMA_PRIORITY_HIGH;
hdma_sai1_a.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
hdma_sai1_a.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_sai1_a.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_sai1_a.Init.PeriphBurst = DMA_PBURST_SINGLE;
SAI is configured as:
hsai_BlockB1.
Instance
= SAI1_Block_B;
hsai_BlockB1.
Init
.
Protocol
= SAI_SPDIF_PROTOCOL;
hsai_BlockB1.
Init
.
AudioMode
= SAI_MODEMASTER_TX;
hsai_BlockB1.
Init
.
Synchro
= SAI_ASYNCHRONOUS;
hsai_BlockB1.
Init
.
OutputDrive
= SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockB1.
Init
.
FIFOThreshold
= SAI_FIFOTHRESHOLD_EMPTY;
hsai_BlockB1.
Init
.
AudioFrequency
= SAI_AUDIO_FREQUENCY_96K;
hsai_BlockB1.
Init
.
SynchroExt
= SAI_SYNCEXT_DISABLE;
hsai_BlockB1.
Init
.
MonoStereoMode
= SAI_STEREOMODE;
hsai_BlockB1.
Init
.
CompandingMode
= SAI_NOCOMPANDING;
Start of the SAI is done with:
HAL_SAI_Transmit_DMA(&hsai_BlockA1, (
uint8_t
*)Audio_output_bufferA, AUDIO_OUTPUT_BUF_SIZE*2);
Full code is here:
#spdif #sai2016-11-21 12:18 PM
You can also see in the big zoom that the signal is perfectly continuous. In case of buffer underrun/overrun, you expect some discontinuity in the signal...
Looking at the specs of the SPDIF interface, I wonder if it could be related to some protection scheme of the consumer type SPDIF interface. I currently don' t manage the Channel Status bits. Could it trigger some faults in my SPDIF receiver like the ones in the above attachments? JMF2016-11-22 10:55 AM
Solved !!!!
You can have a look athttp://www.eevblog.com/forum/microcontrollers/stm32-sai-spdif_tx-issue/
or I was writing by error randomly in the SPDIF Channel Status bits and tickling the ''pre-emphasis'' bit, having the de-emphasis filter switching on and off. I now have a USB Asynch => DSP => 4 digital channels is perfectly reproducing the music on a 20$ stm32 Nucleo board. JMF2016-11-22 12:01 PM
Thanks for coming back with the solution.
JW