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

#include "../mscbemb.h"
#include "CMB_SPI_handler.h"

Functions

void CMBSPI_Init (void)
void CMBSPI_ClockOnce (void)
void CMBSPI_WriteByte (unsigned char dataToSend)
unsigned char CMBSPI_ReadByteRising (void)

Variables

sbit CMBSPI_SCK = CMB_SPI_SCK
sbit CMBSPI_MISO = CMB_SPI_MISO
sbit CMBSPI_MOSI = CMB_SPI_MOSI

Function Documentation

void CMBSPI_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(CMBSPI_DELAY);
00058   CMBSPI_SCK = 1;
00059   delay_us(CMBSPI_DELAY);
00060   CMBSPI_SCK = 0;
00061 }

void CMBSPI_Init ( void   ) 

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

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

unsigned char CMBSPI_ReadByteRising ( void   ) 

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

void CMBSPI_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      CMBSPI_MOSI = (dataToSend >> i) & 0x01;
00077      CMBSPI_ClockOnce();
00078   }
00079   CMBSPI_MOSI = 0;
00080 }


Variable Documentation

sbit CMBSPI_MISO = CMB_SPI_MISO

sbit CMBSPI_MOSI = CMB_SPI_MOSI

sbit CMBSPI_SCK = CMB_SPI_SCK

Setting the related pins of SPI protocol


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7