/home/daqweb/fgddaq/c8051/Protocols/LPB_SPI_handler.h File Reference


Defines

#define LPBSPI_DELAY   50
#define LPBSPI_HALF_DELAY   25
#define LPBSPI_WADDRESS   0x01
#define LPBSPI_RADDRESS   0x02
#define LPBSPI_RSTATUS   0x05

Functions

void LPBSPI_Init (void)
void LPBSPI_ClockOnce (void)
void LPBSPI_WriteByte (unsigned char dataToSend)
unsigned char LPBSPI_ReadByteRising (void)

Define Documentation

#define LPBSPI_DELAY   50

#define LPBSPI_HALF_DELAY   25

#define LPBSPI_RADDRESS   0x02

#define LPBSPI_RSTATUS   0x05

#define LPBSPI_WADDRESS   0x01


Function Documentation

void LPBSPI_ClockOnce ( void   ) 

Generating the SPI communication clock."SFRPAGE = SPI0_PAGE" makes sure that we are in the right page to properly communicate with the SPI protocol.

Attention:
The SPI clock is currently running at 50us.
00056 {
00057   delay_us(LPBSPI_DELAY);
00058   LPBSPI_SCK = 1;
00059   delay_us(LPBSPI_DELAY);
00060   LPBSPI_SCK = 0;
00061 }

void LPBSPI_Init ( void   ) 

Initializing the SPI communication by pulling the SPI Master Output Slave Input (MOSI) pin to 1.

00042 {
00043   SFRPAGE  = SPI0_PAGE ;
00044 //  LPBSPI_MOSI = 1;          //pull the MOSI line high
00045 }

unsigned char LPBSPI_ReadByteRising ( void   ) 

00085 {
00086   signed char i = 0;
00087   unsigned char din = 0;
00088   unsigned char dataReceived = 0;
00089 
00090   for(i = 7; i >= 0; i--)
00091   {
00092           delay_us(LPBSPI_DELAY);
00093     din = LPBSPI_MISO;
00094     dataReceived |= (din << i);
00095         LPBSPI_SCK = 1;
00096         delay_us(LPBSPI_DELAY);
00097         LPBSPI_SCK = 0;
00098  
00099   }
00100   return dataReceived;
00101 }

void LPBSPI_WriteByte ( unsigned char  dataToSend  ) 

Performing SPI write operation.One byte of data transmits in a bit wise fashion

Parameters:
dataToSend One byte of information which has to be sent via SPI protocol.
Returns:
The function does not return any value.
00072 {
00073   signed char i;
00074 
00075   for(i = 7; i >= 0; i--) {
00076      LPBSPI_MOSI = (dataToSend >> i) & 0x01;
00077      LPBSPI_ClockOnce();
00078   }
00079   LPBSPI_MOSI = 0;
00080 }


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7