I2S Bidirectional communication via SAI2 in sln-local2-iot

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2S Bidirectional communication via SAI2 in sln-local2-iot

4,097 Views
Blackpearl
Contributor II

Hi All,

I want to configure SAI2 in sln-local2-iot which is connected to DMIC in evk board as an interface for the communication with the host processor as follows.

Untitled Diagram-Page-3.drawio.png

Pinmuxing is done as follows. 

SAI2_TX_DATA   - GPIO_AD_B0_09-Jtag TDI pin
SAI2_TX_BCLK   - GPIO_AD_B0_05-Boot pin
SAI2_TX_SYNC - GPIO_AD_B0_04-Boot pin
SAI2_RX_DATA - GPIO_AD_B0_08 - DMIC pin

I Tried to record  DMIC data from SAI1  using SLN_AMP_Write() in the host processor via SAI2 .But data is not coming  out of the TX_DATA pin. Only BCLK and FYNC is coming. I am also using Jtag for debugging.Is that making any issue ?Could you please help  me to figure out the issue?What all configuration is needed for the SAI2 to communicate with the host processor?

 

 

0 Kudos
22 Replies

3,927 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl ,

   Thank you for your interest in the NXP MIMXRT product, I would like to provide service for you.

    I have a question for you, do you have tested the SAI2 to your host directly, I mean, prepare the data in the array, then send the audio data through the SAI2 directly, whether this method works or not?

    I think after you make this work, then you just need to check your DMIC-SAI1 whether preparing the working data buffer is OK. 

   So, please test your SAI2 directly with the fixed data buffer, after that works, then add your DMIC data to transfer to the SAI2.

 

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

0 Kudos

3,916 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

I also tested sending a pattern via SAI2 .But that also didn't work.

0 Kudos

3,905 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl ,

   That means your SAI2 configuration have issues.

   In my memory, one of your colleague has tested the specific SAI, and it works OK.

   You can refer to my post about the basic SAI to test it:

https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/RT10xx-SAI-basic-and-SDCard-wave-file-play/ta-p/...

  If you still have issues, just tell me which detail SAI2 pin you are using, the data sample rate, channel, then I will help you to check it.

Best Regards,

Kerry

0 Kudos

3,897 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

I have done as per the link you shared .Now we are not getting even the bclk and fsync.I have  attached the clock_config.c ,pin_mux.c and peripherals.c.Kindly go through it.In the main function we have given the following function calls.

BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_BootClockRUN();
BOARD_InitBootPeripherals();

EnableIRQ(SAI2_IRQn);
SAI_TxEnableInterrupts(SAI2,kSAI_FIFOErrorInterruptEnable);
memset(dummy,0xAA, 320);
xfer.dataSize = 320;
xfer.data = dummy;
while (1)
{

SAI_TransferSendEDMA(DEMO_SAI, &SAI2_SAI_Tx_eDMA_Handle, &xfer);
}

 

Could you please help me to resolve the issue?

 

0 Kudos

3,881 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl 

  Change your SAI pinmux.c configuration:

IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_04_SAI2_TX_SYNC, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_05_SAI2_TX_BCLK, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_08_SAI2_RX_DATA, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_09_SAI2_TX_DATA, 1U);

 

IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_33_SAI3_RX_DATA, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_36_SAI3_TX_DATA,1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_37_SAI3_MCLK, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_38_SAI3_TX_BCLK, 1U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_39_SAI3_TX_SYNC, 1U);

Then test it again.

Now, you just SAI2 don't work, right?

The used pin is:

AD_B0_04_SAI2_TX_SYNC
AD_B0_05_SAI2_TX_BCLK
AD_B0_08_SAI2_RX_DATA
AD_B0_09_SAI2_TX_DATA

You didn't configure the SAI2 MCLK pin?

When you use the local2 board, how do you connect it, please also give me a connection photo of your board.

Best Regards,

Kerry

 

0 Kudos

3,873 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

We have tried as per your suggestions.I am attaching the pin_mux.c along with this.Could you please check ?

We are doing on a custom board.In our custom board SAI2 is the interface for communicating with the host processor .Connection is as follows.

Untitled Diagram-Page-3.drawio.png

0 Kudos

3,868 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl ,

   Thanks for your information.

 OK, if it is the customer board, do you have the logic analyzer?

   If yes, connect the logic analyzer to your SAI2 related interface, check whether the BCLK, SYNC, TX_DATA have data or not?

   Then share your test wave with me.

Best Regards,

Kerry

0 Kudos

3,863 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

Actually we are using customised board.In that SAI2 is taken for the communication with the host processor.We are getting Fsync and BCLK .But TX_DATA is not coming out of the pins.Jtag TDI pin is configured as TX_DATA.Is that making any issue?Or any improperly configured handler function making the issue?

0 Kudos

3,838 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl 

  Please check my attached RT1060 SAI2 code, which I created previously for other SAI testing, I can make sure it can output the data.

  You need to modify the folder xip evkmimxrt1060_flexspi_nor_config.c as your flash code.

  In fact, I find my project is using the same pins as your SAI2. So TX_DATA is the same pin as Jtag TDI, it doesn't matter, as you are using SWD, not JTAG.

  Please try it, after you find my code can output the SAI data, then you can change the word width, data channel, and sample rate as your desired one. The output sai data list in the music.h

Wish it helps you!

Best Regards,

Kerry

 

0 Kudos

3,831 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

Thank you for the response. I have modified xip folder with our flash code.But not able to flash the binary.We are getting the following error.Please help.

Blackpearl_0-1645014858797.png

 

0 Kudos

3,809 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

Could you please update on the above query?

 

0 Kudos

3,784 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl ,

   Sorry for my later reply!

   These days, too many cases in the queue, really a little overflow.

   About the downloading, which debugger you are using now? You also need to change the flashdriver to download the code, your customer board, please tell me which flash you are using? hyperflash the same as sln-local2-iot?

  If you are using the jlink debugger, change the device to RT106S, then it will use the hyperflash.

kerryzhou_0-1645150187563.png

  As RT1060evk is using the qspi flash in default, so the flashdrive is also using the qspi in default, that's why your download have issues.

   If you use the cmsis-dap and hyperflash, note this one:

kerryzhou_1-1645150292700.png

 

Wish it helps you!

Best Regards,

Kerry

 

   

0 Kudos

3,739 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

Thank you for the response.We are able to record TX_DATA at host processor.ie NXP(SLN-LOCAL2-IOT) sends data and host processor record the data.Next I need to validate the data which is sending from host processor is getting properly at NXP side.For this I created a rx_callback function and whatever data  is coming in the SAI2 will be sent to host processor itself(loopback).But no data is coming at host processor.

void rx_callback(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData)
{
uint8_t buffer[960]={0};
sai_transfer_t xfer;
if (kStatus_SAI_RxError == status)
{
}
else
{

xfer.data = buffer ;
xfer.dataSize = 960;
if (kStatus_Success == SAI_TransferReceiveEDMA(DEMO_SAI, &SAI2_SAI_Rx_eDMA_Handle, &xfer))
{
SAI_TransferSendEDMA(DEMO_SAI, &SAI2_SAI_Tx_eDMA_Handle, &xfer);
}

}
}

Could you please help me to resolve the issue?How can we know that  data from host processor is receiving from host processor at rx_data pin of NXP?How is the DMA call back works for the RX_DATA?

0 Kudos

3,704 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

Could you please help me?I am really stuck on this.My configurations for receiver callback is wrong somewhere else.Tx callback is working.What all configurations needed for the SAI2 rx callback?I am really newbie to this.Please do help me.

0 Kudos

3,691 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl ,

   I understand your function, you want to receive the SAI data, then send it back to your host.

   Please refer to my attached code, in fact, the previous MIMXRT1062_SAI2_master_SYNC.zip and this attached code is used to realize this function:

kerryzhou_0-1645503596382.jpeg

These code is what I help the customer do in the previous time, do you can refer to my RT1050 code for your new requirement.

Best Regards,

Kerry

 

 

0 Kudos

3,671 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

I tried this way also.But rx_callback() is not getting called while SAI_TransferReceiveEDMA() executes.What could be the issue?

0 Kudos

3,663 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl ,

   Previously, my code and test can receive the data and transfer the data out, this is the wave:

48K32bit_sync_64bitcheck.jpg

It is 48K sample rate, 4 ch, 32bit bit width.

So, if your external host didn't send the correct format data, then the receive may miss.

Now, you need to know, what your host sai master send data, sample rate, channel, bit width, you also need to connect the correct pins. and test the SAI wave.

If your host SAI master is fixed, then you can modify my code which share with you by yourself to match your own data, then I think you can make it work, please check more details about my shared code, thanks. And also do the I2S bus data testing and analysis, in fact, the SAI is not complicated.

If you need any help from my side, just kindly let me know.

Best Regards,

Kerry

0 Kudos

3,537 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

Sorry for the late reply.Host processor audio parameters like sample rate,bit width etc are same as that of NXP side.But still I am not able to read the data playing from host processor.rx_callback is not getting called when SAI_TransferReceiveEDMA() executes.Is any interrupt handling required for SAI2 RX?I have noticed that only one SAI2_IRQn interrupt is for both sai2 rx and tx .There is no separate rx and tx interrupts.Is that causing any issue?I am attaching sln-local2-iot sdk for your reference. Could you please check it and help me to resolve the issue?

 

Thanks in adavnce

0 Kudos

3,516 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Blackpearl ,

   Do you check the host sendout SAI data wave? You can also share the wave to me, I can help you to check it, whether it match to the slave code. My slave code has been tested with the MIMXRT1060-EVK and the MIMXRT1050-EVKB, and I can make sure RT1050-EVKB can receive the data and send out the data, the previous TX data is my slave received data and send it out.

   So, the rx_callback also can be triggered.

   BTW, if your reply need long time, it's better to create a new question post, as our working flow, one case can't be opened too long time, thanks a lot for your understanding.

Best Regards,

Kerry

0 Kudos

3,146 Views
Blackpearl
Contributor II

Hi @kerryzhou ,

Sorry for the late reply.I have verified hardware connection between NXP and host processor by probing the SAI2_RX_DATA  at TP22. Also double cconfirmed by configuring SAI2_RX_DATA as GPIO I/P.But while debugging we have seen that xfer.data (SAI_TransferReceiveEDMA(SAI2, &SAI2_SAI_Rx_eDMA_Handle, &xfer)) is always zero.Seems it as a configuration issue. Rx configuration and code snippet for receiving and sending the data is given below

RX configuration

sai_transceiver_t SAI2_Rx_config = {
.masterSlave = kSAI_Master,
.bitClock = {
.bclkSrcSwap = false,
.bclkSource = kSAI_BclkSourceBusclk,
.bclkPolarity = kSAI_PolarityActiveLow,
.bclkInputDelay = false
},
.frameSync = {
.frameSyncWidth = 16U,
.frameSyncPolarity = kSAI_PolarityActiveLow,
.frameSyncEarly = true,
},
.syncMode = kSAI_ModeAsync,
.channelMask = kSAI_Channel0Mask,
.startChannel = 0U,
.endChannel = 0U,
.channelNums = 1U,
.serialData = {
.dataMode = kSAI_DataPinStateTriState,
.dataWord0Length = (uint8_t)kSAI_WordWidth16bits,
.dataWordNLength = (uint8_t)kSAI_WordWidth16bits,
.dataWordLength = (uint8_t)kSAI_WordWidth16bits,
.dataOrder = kSAI_DataMSB,
.dataFirstBitShifted = 16U,
.dataWordNum = 2U,
.dataMaskedWord = 0x0U
},
.fifo = {
.fifoWatermark = 16U,
.fifoPacking = kSAI_FifoPackingDisabled,
.fifoContinueOneError = false

}

};

Code snippet

while (1)
{
xfer.data = Buffer + rx_index * BUFFER_SIZE;
xfer.dataSize = BUFFER_SIZE;
if (kStatus_Success == SAI_TransferReceiveEDMA(DEMO_SAI, &rxHandle, &xfer))
{
rx_index++;
}
if (rx_index == BUFFER_NUMBER)
{
rx_index = 0U;
}
xfer.data = Buffer + tx_index * BUFFER_SIZE;
xfer.dataSize = BUFFER_SIZE;
if (kStatus_Success == SAI_TransferSendEDMA(DEMO_SAI, &txHandle, &xfer))
{
tx_index++;
}
if (tx_index == BUFFER_NUMBER)
{
tx_index = 0U;
}
}

Could you please help me to resolve the issue?

Thanks in advance

0 Kudos