Skip to main content
BSchm.6
Associate II
May 31, 2023
Question

Receiving Zeros via SPDIF with STM32F446 does not work

  • May 31, 2023
  • 4 replies
  • 1388 views

I'm using an STM32F446RE to receive data via SPDIF. This works well with the following initialisation:

hspdif.Instance = SPDIFRX;
 hspdif.Init.InputSelection = SPDIFRX_INPUT_IN0;
 hspdif.Init.Retries = SPDIFRX_MAXRETRIES_15;
 hspdif.Init.WaitForActivity = SPDIFRX_WAITFORACTIVITY_ON;
 hspdif.Init.ChannelSelection = SPDIFRX_CHANNEL_A;
 hspdif.Init.DataFormat = SPDIFRX_DATAFORMAT_MSB;
 hspdif.Init.StereoMode = SPDIFRX_STEREOMODE_ENABLE;
 hspdif.Init.PreambleTypeMask = SPDIFRX_PREAMBLETYPEMASK_OFF;
 hspdif.Init.ChannelStatusMask = SPDIFRX_CHANNELSTATUS_OFF;
 hspdif.Init.ValidityBitMask = SPDIFRX_VALIDITYMASK_OFF;
 hspdif.Init.ParityErrorMask = SPDIFRX_PARITYERRORMASK_OFF;
 if (HAL_SPDIFRX_Init(&hspdif) != HAL_OK)

...and with the following code (just some snippets to demonstrate what is going on):

void HAL_SPDIFRX_RxCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
{
	spdifRecvComplete=1;
}
 
...
 
 if (HAL_SPDIFRX_ReceiveDataFlow_IT(&hspdif,recvBuffer[currBuff],spdifBufferSize)==HAL_OK)
 {
 spdifRecvComplete=0;
 currBuff=1-currBuff;
 }
 
...
 
 while (1)
 {
 if (spdifRecvComplete)
 {
 if (HAL_SPDIFRX_ReceiveDataFlow_IT(&hspdif,recvBuffer[1-currBuff],spdifBufferSize)==HAL_OK)
 {
 spdifRecvComplete=0;
...

Within my recvBuffer I can see the received audio data in the upper 20 bits and the flags/auxiliary bits in the lower 12 bits of the 32bit received data.

But when the incoming data except the Valid-bit all are 0 (means the device on the other end has 0 at Aux, Data and the flags except "Valid"), the interrupt never happens. The preamble of course is still valid, so that proper frames can be detected:


_legacyfs_online_stmicro_images_0693W00000blDM2QAM.png 

So shouldn't this also cause an interrupt to occur when there are enough SPDIF-frames detected? Or is there something special needed in order to receive such 0-data-frames too?

Thanks 

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
June 2, 2023

My SPDIF-fu is rusty, but SPDIF is more than just data, you should also see proper pattern of the preambles, to be able to identify individual blocks. I believe the SPDIF-RX chapter in RM0390 has a quite concise description of the protocol and also how the module indicates various correct and incorrect states.

Cube/HAL and Cube-MX-clicked-code usually does not work well with anything other than usual/expected.

JW

BSchm.6
BSchm.6Author
Associate II
June 5, 2023

From SPDIF-frame's point of view it should be fine, there are valid preambles, the "valid"- and the "parity"-bits are set properly. Just the payload is completely at 0 (including user-, control-bit, data and auxiliary).

waclawek.jan
Super User
June 5, 2023

Well, I don't know answers to your problem, but I'd recommend you to

  • read the SPDIF chapter in RM
  • read and output in real-time the available status information (SPDIFRX_SR)
  • make sure you can map between the Cube/HAL nomenclature and actions, and the RM's nomenclature and description; or simply avoid using Cube/HAL

JW

LCE
Principal II
June 6, 2023

What is your SPDIF source?

I use the SAI SPDIF TX a lot for testing, which is working very reliably, you might try that as a source.

It might be that an idle SPDIF source is sending always zeros, just to let the receiver keep the sync. So maybe there is some setting / bit register on the STM's RX side how to react to an ongoing zero-only input?