Hello, thanks for the reply. I am using nxp sdk 2.16.000, I have rewritten the evk9mimx8ulp_sai_edma_transfer example. I have provided the implementation of the config_sai_tx() and config_sai_tx_edma() functions in the file that I have attached to the first message, and I will also duplicate them at the end of this message.
I have solved the problem with the sample rate for edma by removing the line
config.bitClock.bclkSource = kSAI_BclkSourceBusclk;
in config_sai_tx_edma().
For the option without using edma (config_sai_tx) I think that the problem with the sample rate was caused by calling SAI_TransferSendNonBlocking() too often.
I think the sample rate issue is solved for now, but there is still a problem that when using SAI1 (#define USE_SAI1) I don't get data on the bClk and data pins when using edma (if mclk is turned on i see signal mclk) (function config_sai_tx_edma()) I get a fifo underrun error, it seems that there are some differences in edma initialization for sai1 that I don't know about and therefore edma does not feed data to sai1.
Сode of functions config_sai_tx() and config_sai_tx_edma() :
void config_sai_tx()
{
sai_transfer_t saiXfer;
sai_transceiver_t config;
saiXfer.data = dataForTransfer3;
saiXfer.dataSize = 480;
SAI_Init(CURRENT_SAI);
SAI_TransferTxCreateHandle(CURRENT_SAI, &s_saiTxHandle, saiCallback, NULL);
SAI_GetClassicI2SConfig(&config, kSAI_WordWidth16bits, kSAI_Stereo, SAI_CHANNEL);
config.bitClock.bclkSource = kSAI_BclkSourceBusclk;
config.masterSlave = kSAI_Master;
SAI_TransferTxSetConfig(CURRENT_SAI, &s_saiTxHandle, &config);
SAI_TxSetBitClockRate(CURRENT_SAI, SAI_CLK, kSAI_SampleRate48KHz, kSAI_WordWidth16bits, 2);
for(int i=4;i <saiXfer.dataSize; i++){
dataForTransfer3[i] = 0;
}
int sendCount = 0;
while (true)
{
if (kStatus_Success == SAI_TransferSendNonBlocking(CURRENT_SAI, &s_saiTxHandle, &saiXfer))
{
if (sendCount++ > 1000)
sendCount = 0;
}
}
}
void config_sai_tx_edma()
{
edma_config_t dmaConfig = {0};
sai_transceiver_t config;
EDMA_GetDefaultConfig(&dmaConfig);
EDMA_Init(DMA0, &dmaConfig);
EDMA_CreateHandle(&g_dmaHandle, DMA0, DMA_CHAN);
EDMA_SetChannelMux(DMA0, DMA_CHAN, SAI_DMA_MUX);
SAI_Init(CURRENT_SAI);
SAI_TransferTxCreateHandleEDMA(CURRENT_SAI, &txHandle, dmaCallback, NULL, &g_dmaHandle);
SAI_GetClassicI2SConfig(&config, kSAI_WordWidth16bits, kSAI_Stereo, SAI_CHANNEL);
// config.bitClock.bclkSource = kSAI_BclkSourceBusclk; by removing this line the sample rate became correct
config.masterSlave = kSAI_Master;
config.syncMode = kSAI_ModeAsync;
SAI_TransferTxSetConfigEDMA(CURRENT_SAI, &txHandle, &config);
SAI_TxSetBitClockRate(CURRENT_SAI, SAI_CLK, kSAI_SampleRate48KHz, kSAI_WordWidth16bits, 2);
sai_transfer_t saiXfer2[2];
sai_transfer_t saiXfer;
saiXfer2[0].data = dataForTransfer0;
saiXfer2[1].data = dataForTransfer1;
saiXfer2[0].dataSize = 480;
saiXfer2[1].dataSize = 480;
if (SAI_TransferSendLoopEDMA(CURRENT_SAI, &txHandle, &saiXfer2, 2) != kStatus_Success)
{
bool fail;
fail = true;
};
}