LRC CALCULATION, (CON’T)
The following C language function
is an example of an LRC
calculation program. It accepts two
arguments: a pointer to a buffer
and a buffer length. Its return value
is the LRC value for the specified
buffer.
COMMANDS FROM THE UR5HCSPI-06 TO THE HOST, (CON’T)
Resend Request
<CONTROL>
80H
<RESEND>
A5H
<LRC>
25H
The UR5HCSPI-06 will send this Resend Request Command to the host
when its command buffer is full, or if it detects either a parity error or an
unknown command during a system command transmission.
char Calculate LRC (char buffer,
size buffer)
{
char LRC;
size_t index;
/*
* Init the LRC using the first two
message bytes.
*/
LRC = buffer [0] ^ buffer [1];
/*
* Update the LRC using the
remainder of the buffer.
*/
for (index = 2; index < buffer; index
++)
LRC ^ = buffer[index];
/*
* If the MSB is set then clear the
MSB and change the next most
significant bit
*/
if (LRC & 0x80)
LRC ^ = 0xC0;
/* * Return the LRC value for the
buffer.*/}
Input/Output Mode Status Report
<CONTROL>
80H
<MODIO>
A7H
<IO NUMBER>
xxH IO number, 0
<IO MODE>
xxH IO mode: (0=input; 1=output;
2=switch; 3=LED )
<LRC>
xxH
The UR5HCSPI-06 will send the I/O Mode Status Report to the host when it
receives the I/O Mode Status Request Command from the host, in order to
report the status of the GIO0 pin.
Input/Output Data Report
<CONTROL>
80H
<MODIO>
A8H
<IO NUMBER>
xxH IO number, 0
<IO DATA>
xxH IO data: ( 0=low, 1=high )
<LRC>
xxH
The UR5HCSPI-06 will send the I/O Data Report to the host when it receives
the I/O Data Request Command from the host.
Copyright Semtech 1997-2001
11
DOC5-SPI-06-DS-103
www.semtech.com