How do I know if the SPI slave has received the data?

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

How do I know if the SPI slave has received the data?

Jump to solution
4,866 Views
kbj
Contributor IV

Hi,

I implements SPI slave on S32K144 EVB by using SDK EAR 0.8.6 with S32DS for ARM.2018.R1.

But I don't know how to know the SPI slave received the data.

Is there a function that tells us that the data was received?
Or should I check the chip select PIN?
How do I read the chip select PIN?
Please tell me how to know that the slave has received the data.

Best regards,

Byungju

0 Kudos
1 Solution
4,137 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

you are right. With SDK it is not possible check if slave data are ready - data are automatically passed into receive buffer without any notification. All the LSPI0 register related stuff is done on background. If you need such feature - the only way is write your own driver. You can reuse LPSPI non  SDK example:

pastedImage_1.png

Jiri

View solution in original post

0 Kudos
13 Replies
4,137 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

You can use blocking transfer - the function returns when transfer is done. For non-blocking transfer - you can check status by 

SPI_GetStatus(const spi_instance_t * const instance)

function. If you get STATUS_BUSY - transfer is in progress. 

Hope it helps. 

Jiri 

0 Kudos
4,137 Views
kbj
Contributor IV

Hi Jiri,

Thanks for your help.

When the SPI slave receive a data, do the function, SPI_GetStatus(), return STATUS_BUSY?

Best regards,

Byungju.

0 Kudos
4,137 Views
jiri_kral
NXP Employee
NXP Employee

Hi Byungju

I'm not sure what exactly do you mean - The SDK GetStatus() function returns BUSY when transfer is in progress . This is usable for some kind of message timing (to be sure that previous transfer is done before you start another one) in non-blocking mode.  

If you  mean something like slave acknowledges that data are okay - you need to implement it by yourself in your message protocol (for example slave can send back to master "okay with CRC" message). 

Jiri

0 Kudos
4,137 Views
kbj
Contributor IV

Dear Jiri,

It seems that my question has not been well communicated.
If I implement an SPI slave
When the Master initiates a data transfer, how does the slave detect if the data transfer has started?

BestRegards,

Byungju.

0 Kudos
4,137 Views
jiri_kral
NXP Employee
NXP Employee

Hi Byungju

You can install SPI_Slave callback function and check the events you are interested in.

For example: 

void MySlaveCallback(void *driverState, spi_event_t event, void *userData)
{

   /* Handle your SPI Slave envent here */  

}

SlaveConfig0.callback=&MySlaveCallback;
SPI_SlaveInit(&spi2Instance, &SlaveConfig0);

.

.

Hope it helps. 

Jiri

0 Kudos
4,137 Views
kbj
Contributor IV

Hi Jiri,

Thanks for your help.

I do not know what I made a mistake, but the SPI communication is not stable when using the callback function.
Can you provide example code for SPI communications using the callback function?

I am developing with S32DS for ARM.2018.R1 and SDK EAR 0.8.6.
I am always thankful for your help.

Best regards,

Byungju.

0 Kudos
4,138 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

you are right. With SDK it is not possible check if slave data are ready - data are automatically passed into receive buffer without any notification. All the LSPI0 register related stuff is done on background. If you need such feature - the only way is write your own driver. You can reuse LPSPI non  SDK example:

pastedImage_1.png

Jiri

0 Kudos
4,137 Views
kbj
Contributor IV

Hi Jiri,

Thanks for your help.

If you don't mind, Could you provide a sample code that uses an SPI callback function?

Best regards,

Byungju.

0 Kudos
4,137 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

unfortunately there is no such example ( if you mean by callback function the notification ability when SPI Slave receive data). But you can adapt the example mentioned above and add interrupt handler. 

Jiri

0 Kudos
4,137 Views
kbj
Contributor IV

Hi Jiri,

The example code I want is the example code that uses the call back fucionation of the existing SPI SDK.
Could you provide that example code?

Thanks and best regards,

Byugnju

0 Kudos
4,137 Views
jiri_kral
NXP Employee
NXP Employee

Hi Byugnju, 

sure - project is in attachment. 

Jiri

4,137 Views
kbj
Contributor IV

Hi Jiri,

Thanks for your help.

Best regards,

Byunju.

0 Kudos
4,137 Views
kbj
Contributor IV

Hi Jiri,

Is the callback function called when the slave starts data transfer?
As a result of checking, the callback function was called only when the slave had to transfer data.
My desired behavior is that when the Master starts data transfer, the Callback function is called and the slave starts to transfer data.

ThnkaThanks and best regards,

Byungju.

0 Kudos