SPI从模式DMA通信示例

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

SPI从模式DMA通信示例

2,802 Views
龙开云
Contributor II

因项目紧急,需要申请下SPI从模式DMA通信示例;帮忙提供一下S32K324平台参考;

Labels (1)
0 Kudos
17 Replies

2,736 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @龙开云,

A test project that utilizes S32K344 SPI DMA built with RTD 2.0.2 is attached.

 

BR, Daniel

2,711 Views
龙开云
Contributor II

对于采用DMA方式,  单次传输可以设定1024字节或以上么?  从下图规格说明为512

_1-1694531600361.png

 

 

0 Kudos

2,679 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @龙开云,

This just specifies how much data can be written there in the burst mode.

But the LPSPI module as well as the RTD driver support longer transfers.

 

Regards,

Daniel

0 Kudos

2,583 Views
龙开云
Contributor II

感谢,已经通信正常;

但还存在一个现象就是,一帧数据的第一个字节在master端收到为0x7的值;  这种情况是什么原因?

0 Kudos

2,540 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @龙开云,

Hard to say just from the description.

What should be the first byte send by the Slave device?

Is the TX FIFO filled before the Master starts the transfer?

Do you monitor the bus with a logic analyzer / oscilloscope?

 

BR, Daniel

Tags (1)
0 Kudos

2,477 Views
龙开云
Contributor II

图片为全0的情况下,第一个字节也是0x7

_0-1695724752649.png

 

0 Kudos

2,476 Views
龙开云
Contributor II

使用如下函数进行填充时,是否需要等待,主机端才能读取。

_0-1695724933547.png

 

0 Kudos

2,440 Views
danielmartynek
NXP TechSupport
NXP TechSupport

The function must be called before the master starts the transfer.

Do you use the Lpspi_Ip_GetStatus() to check the transfer?

Does the transfer completed successfully?

 

Thanks,

Daniel

0 Kudos

2,347 Views
龙开云
Contributor II

是的,在master重新请求时,会判断状态。然后重新装载数据。

_0-1696671760559.png

除了首字节为0x7外;   还出现数据master发送时接收不全的问题,前面的几个数据丢失,但是逻辑分析抓到SPI线的数据是正常的;

目前发现速率在100KHz较为稳定,500KHz以上就比较容易出现问题。

0 Kudos

2,280 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @龙开云,

If this failure rate depends on the baud rate, can you examine the SPI signals using an oscilloscope and ensure that it is within the SPI specification (DS rev8, Table 44. LPSPI)

 

Thank you,

BR, Daniel

0 Kudos

2,223 Views
龙开云
Contributor II

两个问题:

问题1.首字节一直为0x7还没回答,先把这个问题解了呗。              问题2.至于SPI传输丢数据现象后面再提吧。

_0-1697872279152.png

 

0 Kudos

2,169 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @龙开云,

What is in the Spi1TxBuffer?

Why do you call the AsyncTransfer() in a while loop?

Also, you cancel the transfer if the GetStatus() function returns other status that IDLE.

You should simply call the AsyncTransfer() once and then poll the GetStatus() function until the transfer is completed, and you have to make sure the AsyncTransfer() function is called before the Master starts the transfer.

 

Please share the project?

 

Regards,

Daniel

0 Kudos

1,915 Views
龙开云
Contributor II

1.Spi1TxBuffer  is 0x00

2.Why do you call the AsyncTransfer() in a while loop?  没有一直loop这个,需要传输新的数据并且上一次传输完成才会调用;

3.是在AsyncTransfer()调用后的时候使用GetStatus()来检测是否空闲。

工程没法共享哦,涉及的代码太多。

主要是第一个位为何会主动拉高一下,因为填充的数据都为0,没理解内部如何产生;

0 Kudos

1,829 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @龙开云,

Is the pointer to Spi1TxBuffer 0x00 (NULL) or is the pointer valid and the content of the buffer is 0x00.

Because if the pointer is NULL, the driver sends the SpiDefaultData.

danielmartynek_0-1701161231976.png

 

Regards,

Daniel

0 Kudos

1,826 Views
龙开云
Contributor II

SPI指向的buff数据内容为0,不是指向空NULL。

SpiDefaultData默认设置也为0;

_0-1701163474247.png

 

0 Kudos

1,821 Views
danielmartynek
NXP TechSupport
NXP TechSupport

It really requires some debugging on your side.

For example, you can use a GPIO to see when the transfer starts and ends.

Use another communication interface to send the state of the LPSPI TX FIFO.

Also, as I mentioned, there are issues in the code you posted, like you cancel the transfer if the function does not return SUCCESS. You disable the interrupt before the code reads the status of the previous transfer in a while loop etc.

I would recommend simplifying the project, and using at least the GPIOs.

I guess there must be some data left in the TX FIFO from a previous transfer when the current transfer starts.

 

Regards,

Daniel

0 Kudos

1,770 Views
龙开云
Contributor II

如下是通过IO检测并装载数据,在装载数据前关闭中断,然后判断SPI是否空闲,之后再装载数据;

最后再开启中断。

请帮忙审核下这样的处理有何不妥之处,如何优化,感谢!

_0-1701342171952.png

我们通过别的方式再查查。

 

0 Kudos