73
SPI Procedures
A1.1 SPI READ/WRITE Pseudo Code
//----------------------------------------------------------------------------
// Write command, SPI module address, register address
// Read data
//----------------------------------------------------------------------------
void SPI_Read(unsigned int COMMAND)
{
unsigned int DATA; //We will read data there
//Write Command and Address (MSB First)
//First 1 bit (MSB) = Command
//Next 15 (LSBs) bits = Register Address
for(int i=15; i>=0; i--)
{
if(i’th bit in COMMAND is ‘1’)
{
Set Data Output line to ‘1’;
}
else
{
Set Data Output line to ‘0’;
};
Apply Rising and Falling CLK signal edges to CLK line;
};
//Read Data (MSB First)
//Note: At this point we have data MSB valid from the chip.
for(int i=15; i>=0; i--)
{
if(there is ‘1’ at the Data Input Line)
{
Set i’th bit in DATA ‘1’;
}
else
{
Set i’th bit in DATA ‘0’;
};
Apply Rising and Falling CLK signal edges to CLK line;
};
};