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

#include "../mscbemb.h"
#include "LPB_SPI_handler.h"

Functions

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

Variables

sbit LPBSPI_SCK = LPB_SPI_SCK
sbit LPBSPI_MISO = LPB_SPI_MISO
sbit LPBSPI_MOSI = LPB_SPI_MOSI

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 }


Variable Documentation

sbit LPBSPI_MISO = LPB_SPI_MISO

sbit LPBSPI_MOSI = LPB_SPI_MOSI

sbit LPBSPI_SCK = LPB_SPI_SCK

Setting the related pins of SPI protocol


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7