How to use SPI_MasterTransferBlocking and SPI_MasterTransfer properly?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to use SPI_MasterTransferBlocking and SPI_MasterTransfer properly?

ソリューションへジャンプ
539件の閲覧回数
AhpKim
Contributor I

Hi, 

I'm trying to use the SPI protocol between the IMU sensor, ASM330LHHX, and my MCU, MPC5748G.

How it's configured :

AhpKim_0-1687226334755.png

CS PIN : SIUL2->GPDO[26]

By using SPI_MasterTransferBlocking, I can send and receive the sensor data.

But the problem is that I can only get the IMU sensor data, and other modules such as CAN protocol and UART protocol stop running.

 

So here're two questions I want to ask,

1. How to stop the SPI_MasterTransferBlocking function properly? This is how I use this function:

AhpKim_0-1687231179125.png

After the transfer, shouldn't it be finished and start running other modules? It seems to have all the usage of the process.

 

2. So I used SPI_MasterTransfer function, but when I raise CS and run the SPI_MasterTransfer function, SPI_MasterTransfer status keep giving me STATUS_BUSY. 

AhpKim_1-1687231719743.pngAhpKim_2-1687231731975.png

Green line is CS, Yellow line is the Clock. 

So CS turned low before the transfer finished. Is there a way to fix this situation?

 

Any help is welcome.

Thanks,

0 件の賞賛
1 解決策
523件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

1) yes, blocking function is waiting inside until all defined number of bytes are sent or timeout expires. But interrupts are still enabled so can be handled normally from other modules. A timeout for the transfer is in milliseconds. If the transfer takes longer than this amount of time, the transfer is aborted and a STATUS_TIMEOUT error returned.

2) if there was no transfer before or it was already finished then function should not return STATUS_BUSY, rather STATUS_SUCCESS. For non-blocking function you should test for end of transfer before it can be again called, for example by using DSPI_GetTransferStatus function. For example like below, to ensure transfer is finished and CS (if driven my SW) can be deasserted.

dspi_transfer_status_t status=DSPI_TRANSFER_OK;

SIUL2->GPDO[24]=0;
DSPI_MasterTransfer(SPI0_INSTANCE, master_send, master_receive, 2);
do
{
DSPI_GetTransferStatus(SPI0_INSTANCE, &status);
}while(status==DSPI_IN_PROGRESS);
SIUL2->GPDO[24]=1;

BR, Petr 

元の投稿で解決策を見る

0 件の賞賛
2 返答(返信)
524件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

1) yes, blocking function is waiting inside until all defined number of bytes are sent or timeout expires. But interrupts are still enabled so can be handled normally from other modules. A timeout for the transfer is in milliseconds. If the transfer takes longer than this amount of time, the transfer is aborted and a STATUS_TIMEOUT error returned.

2) if there was no transfer before or it was already finished then function should not return STATUS_BUSY, rather STATUS_SUCCESS. For non-blocking function you should test for end of transfer before it can be again called, for example by using DSPI_GetTransferStatus function. For example like below, to ensure transfer is finished and CS (if driven my SW) can be deasserted.

dspi_transfer_status_t status=DSPI_TRANSFER_OK;

SIUL2->GPDO[24]=0;
DSPI_MasterTransfer(SPI0_INSTANCE, master_send, master_receive, 2);
do
{
DSPI_GetTransferStatus(SPI0_INSTANCE, &status);
}while(status==DSPI_IN_PROGRESS);
SIUL2->GPDO[24]=1;

BR, Petr 

0 件の賞賛
490件の閲覧回数
AhpKim
Contributor I

Thanks!! It worked!!

0 件の賞賛