How to use SPI_MasterTransferBlocking and SPI_MasterTransfer properly?

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

How to use SPI_MasterTransferBlocking and SPI_MasterTransfer properly?

Jump to solution
591 Views
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 Kudos
1 Solution
575 Views
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 

View solution in original post

0 Kudos
2 Replies
576 Views
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 Kudos
542 Views
AhpKim
Contributor I

Thanks!! It worked!!

0 Kudos