2.5.2 SPI Software Implementation
The following code demonstrates how to implement SPI communication in software for the host
system, e.g. for a microcontroller:
byte SPI_ReadWrite(byte
{
byte
i;
for
(i=0; i<8; i++)
{
if
(Data & 0x80)
else
SCK_HIGH;
Data <<= 1;
if
(READ_MISO)
SCK_LOW;
}
return
Data;
}
int
main(void)
{
byte
k;
byte
q;
byte
LengthByteRead;
byte
LengthByteWrite;
// ...
while(1)
{
LengthByteWrite = GetNumBytesInSendBuffer();
SS_LOW;
LengthByteRead = SPI_ReadWrite(LengthByteWrite);
while
{
}
SS_HIGH;
}
// ...
}
Data)
MOSI_HIGH;
MOSI_LOW;
Data |= 0x01;
((LengthByteRead > 0) || (LengthByteWrite > 0))
if
(LengthByteWrite > 0)
{
q = GetByteFromSendBuffer();
LengthByteWrite--;
}
else
q = 0x00;
k = SPI_ReadWrite(q);
if
(LengthByteRead > 0)
{
LengthByteRead--;
PushByteToReceiveBuffer(k);
}
else
LengthByteRead = k;
Elatec GmbH
Page 11 of 61
Need help?
Do you have a question about the TWN3 Mini Reader Mifare NFC and is the answer not in the manual?