Hi @Ayse ,
The TDM interface seems correctly set. To be sure, you can read the registers with address:
And check with the datasheet if they are set as you like.
To read the data, it's possible to use the SAI interface. ST’s boards have the possibility to use the HAL, so function that abstract the hardware layer to simplify the development. You can connect the SAI interface in use to a DMA , so a memory space, and when the data is ready the HAL that manages the SAI interface call a function. When the function is called, you have the possibility to use memcpy to save the data into an array previously defined. The peripheral initialization connects the interface to the DMA so when the DMA is ready triggers a function defined as in the following example.
(Define and variable section)
#define FIFO_SIZE 1000
typedef union{
struct{
int16_t x;
int16_t y;
int16_t z;
};
uint8_t b8[6];
}out;
static out bs[FIFO_SIZE] = {0};
static int16_t bb_tdm[3];
static uint32_t i_w_tdm = 0;
(Outside main)
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
{
memcpy(&bs[i_w_tdm].x,&bb_tdm[0],3);
i_w_tdm = (i_w_tdm + 1);
}
(Inside main):
HAL_SAI_Receive_DMA(&hsai_BlockA1,(uint8_t*)bb_tdm,6);
The function called into the main starts the SAI interface and tells the peripheral to store the 6 blocks of data into the DMA at the address of bb_tdm.
Blocks are 6 instead of 3 because the address is incremented as uint8_t so an int16_t value need two increments to be copied.
When all data is transmitted correctly, the DMA calls the function defined outside the main. This function stores the data into the struct in position i_w_tdm using the memcpy instruction.
In this way the three channels of TDM data are stored and available for reading.
If this helps you, please mark my answer as "Best Answer" by clicking on the "Accept as Solution" button, this can be helpful for Community users to find this solution faster.