Function |
|
Update SPI flags and packet length and check whether SPI is busy |
Purpose |
|
Provide application program with information about current SPI status |
Syntax |
|
bit getStatusSPI() |
Parameters |
|
– |
Return value |
|
• 1 – SPI busy • 0 – SPI not busy |
Output values |
|
• SPIpacketLength: received packet length • param2.3 (_SPIRX): 1 – Something received on SPI. • param2.4 (_SPICRCok): 1 – The last received SPI CRCM was O.K. |
Preconditions |
|
SPI must be enabled by enableSPI |
Remarks |
|
• Output values (param2) have a different format than the SPI status sent to the Master. • See IQRF SPI Technical guide and Example E07-SPI. |
Side effects |
|
– |
See also |
|
|
Example 1 |
|
// Master -> Slave enableSPI(); // Master is allowed to transmit from now
Receive: clrwdt(); if (getStatusSPI()) // Wait until SPI is not busy goto Receive;
if (_SPIRX) // Anything received? { // Yes: if (!_SPICRCok) // CRCM matched? { // No: startSPI(0); // Restart SPI goto Receive; // and try to receive again. } // Yes: // BufferCOM is automatically protected now // not to be overwritten by next SPI packet. // Thus, stopSPI is not necessary here. // Packet length is in SPIpacketLength. copyBufferCOM2INFO(); // Store received packet startSPI(0); // and then allow Master to transmit again. } else goto Receive; // Nothing received yet
// ... Continue here after successful receiving
waitMS(1); // Time for finishing startSPI(0) on background disableSPI(); // otherwise Master's CRCS check fails. // The delay depends on the Master application. |
Example 2 |
|
enableSPI(); startSPI(2); // 2 B to send to master while (getStatusSPI()) // Wait until SPI is not busy waitMS(1); ... // Now the transfer is finished |