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

#include "../mscbemb.h"
#include "SPI_handler.h"

Functions

void SPI_Init (void)
void SPI_ClockOnce (void)
void SPI_WriteByte (unsigned char dataToSend)
void SPI_WriteUInt (unsigned int dataToBeSend)
unsigned char SPI_ReadByteRising (void)

Variables

sbit SPI_SCK = MSCB_SPI_SCK
sbit SPI_MISO = MSCB_SPI_MISO
sbit SPI_MOSI = MSCB_SPI_MOSI

Function Documentation

void SPI_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.
00059 {
00060   SFRPAGE = SPI0_PAGE;
00061   delay_us(SPI_DELAY);
00062   SPI_SCK = 1;
00063   delay_us(SPI_DELAY);
00064   SPI_SCK = 0;
00065 }

void SPI_Init ( void   ) 

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

00042 {
00043   SFRPAGE  = SPI0_PAGE ;
00044   SPI_MOSI = 1;          //pull the MOSI line high
00045 #ifdef AD5300
00046   SPI_SCK = 1;
00047 #endif
00048 }

unsigned char SPI_ReadByteRising ( void   ) 

00144 {
00145   signed char i = 0;
00146   unsigned char din = 0;
00147   unsigned char dataReceived = 0;
00148 
00149   SFRPAGE = SPI0_PAGE ;
00150   for(i = 7; i >= 0; i--)
00151   {
00152         delay_us(SPI_DELAY);
00153    din = SPI_MISO;
00154    dataReceived |= (din << i);
00155         SPI_SCK = 1;
00156         delay_us(SPI_DELAY);
00157         SPI_SCK = 0;
00158  
00159   }
00160   return dataReceived;
00161 }

void SPI_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.
00077 {
00078   signed char i;
00079 
00080   SFRPAGE = SPI0_PAGE ;
00081   for(i = 7; i >= 0; i--) {
00082      SPI_MOSI = (dataToSend >> i) & 0x01;
00083      SPI_ClockOnce();
00084   }
00085   SPI_MOSI = 0;
00086 }

void SPI_WriteUInt ( unsigned int  dataToBeSend  ) 

Performing SPI write operation.Two bytes of data transmits in a bit wise fashion

Parameters:
dataToSend Two byte of information which has to be sent via SPI protocol.
Returns:
The function does not return any value.
00099 {
00100         signed char i;
00101         
00102   SFRPAGE = SPI0_PAGE ;
00103   
00104   for(i = 15; i >= 0; i--) {       
00105           SPI_MOSI = (dataToBeSend >> i) & 0x01;
00106      SPI_ClockOnce();
00107   }
00108   SPI_MOSI = 0;
00109 }


Variable Documentation

sbit SPI_MISO = MSCB_SPI_MISO

sbit SPI_MOSI = MSCB_SPI_MOSI

sbit SPI_SCK = MSCB_SPI_SCK

Setting the related pins of SPI protocol


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7