I'm trying to implement a protocol defined like this:
The Reply T1 and Reply T2 messages are sent one after the other to the master processor in response to a pair of poll messages (0xEAEA, 0xEAEA), OR a single poll followed by an acknowledgement (0xEAEA, 0x8001). The reply to the first poll message will the T1 reply. If the T1 reply indicates a specific condition (bit 10 on), then the second message from the master will be an acknowledgement instead of a poll. The response to the second message of the pair sent by the master will a T2 type of reply.
The T1 message hi nibble is 0x8 while the T2 message hi nibble is C or D
What I see in the LA trace is:
Time [s],Packet ID,MOSI,MISO
0.034181000000000,0,0xEAEA,0xDFC5
0.034562000000000,0,0xEAEA,0xDFC5
0.096511000000000,0,0xEAEA,0xC1ED
0.096893000000000,0,0xEAEA,0xC1ED
0.159001000000000,0,0xEAEA,0x8006
0.159382000000000,0,0xEAEA,0x8006
0.221522000000000,0,0xEAEA,0x8A09
0.221903000000000,0,0xEAEA,0x8A09
0.284139000000000,0,0xEAEA,0xC123
0.284520000000000,0,0xEAEA,0xC123
0.346660000000000,0,0xEAEA,0x8016
0.347041000000000,0,0xEAEA,0x8016
0.409213000000000,0,0xEAEA,0x8A22
0.409594000000000,0,0xEAEA,0x8A22
Which is not quite as I expect!
My code looks like:
bool T1MessageSet = false;
in main loop:
if (_SPIRBF) SPI_Received = SPI1BUF; // Read SPI input into buffer
if (0 != SPI_Received && !_SPITBF)
{
request = SPI_Received & 0xF000;
value = SPI_Received & Request_Data_Mask;
switch (request)
{
:
: many cases not shown
:
//
// A poll request (0xEAEA) or a Stall acknowledgement
//
case Request_Info:
case Request_Ack:
if (Request_Info == request && !T1MessageSent)
{
//
// Always send the Type 1 message in reply to 1st poll
//
reply = T1Data;
T1MessageSent = true;
}
else
{
//
// Check if we have a stall acknowledgement
//
if (0x8001 == SPI_Received) Stall_Ack = true;
//
// Message should be a poll or a stall acknowledgement
//
if (0x8001 == SPI_Received ||
(Request_Info == request && T1MessageSent))
{
//
reply = T2Data;
}
else reply = 0;
T1MessageSent = false;
}
break;
default:
break;
}
SPI1BUF = reply;
}
Clearly there's a an error in there somewhere, but for the life of me I cannot see what it is!
Any help most welcome
Thanks
David