Defines | |
| #define | CMBSPI_DELAY 50 |
| #define | CMBSPI_HALF_DELAY 25 |
| #define | CMBSPI_WADDRESS 0x01 |
| #define | CMBSPI_RADDRESS 0x02 |
| #define | CMBSPI_RSTATUS 0x05 |
Functions | |
| void | CMBSPI_Init (void) |
| void | CMBSPI_ClockOnce (void) |
| void | CMBSPI_WriteByte (unsigned char dataToSend) |
| unsigned char | CMBSPI_ReadByteRising (void) |
| #define CMBSPI_DELAY 50 |
| #define CMBSPI_HALF_DELAY 25 |
| #define CMBSPI_RADDRESS 0x02 |
| #define CMBSPI_RSTATUS 0x05 |
| #define CMBSPI_WADDRESS 0x01 |
| 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.
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
| dataToSend | One byte of information which has to be sent via SPI protocol. |
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 }
1.4.7