This is an involuntary fork, created because the repository would not update mmSPI. SPI library used to communicate with an altera development board attached to four zigbee-header pins.

Dependents:   Embedded_RTOS_Project

Fork of mmSPI by Mike Moore

Committer:
gatedClock
Date:
Wed Aug 14 14:47:12 2013 +0000
Revision:
4:aa1fe8707bef
Parent:
3:de99451ab3c0
Child:
5:b14dcaae260e
mmSPI::setSPIfrequency(float fFreq)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gatedClock 0:fb42c5acf810 1 /*----------------------------------------------//------------------------------
gatedClock 0:fb42c5acf810 2 student : m-moore
gatedClock 0:fb42c5acf810 3 class : external SPI interface
gatedClock 0:fb42c5acf810 4 directory : mmSPI
gatedClock 0:fb42c5acf810 5 file : mmSPI.cpp
gatedClock 0:fb42c5acf810 6 ------------------------------------------------//----------------------------*/
gatedClock 0:fb42c5acf810 7 #include "mmSPI.h"
gatedClock 0:fb42c5acf810 8 /*----------------------------------------------//------------------------------
gatedClock 0:fb42c5acf810 9 ------------------------------------------------//----------------------------*/
gatedClock 0:fb42c5acf810 10 //==============================================//==============================
gatedClock 0:fb42c5acf810 11 mmSPI::mmSPI() // constructor.
gatedClock 0:fb42c5acf810 12 {
gatedClock 3:de99451ab3c0 13 allocations(); // object allocations.
gatedClock 0:fb42c5acf810 14 }
gatedClock 0:fb42c5acf810 15 //----------------------------------------------//------------------------------
gatedClock 0:fb42c5acf810 16 mmSPI::~mmSPI() // destructor.
gatedClock 0:fb42c5acf810 17 {
gatedClock 3:de99451ab3c0 18 if (pMOSI) {delete pMOSI; pMOSI = NULL;} // delete allocation.
gatedClock 3:de99451ab3c0 19 if (pMISO) {delete pMISO; pMISO = NULL;} // delete allocation.
gatedClock 3:de99451ab3c0 20 if (pSCLK) {delete pSCLK; pSCLK = NULL;} // delete allocation.
gatedClock 3:de99451ab3c0 21 }
gatedClock 3:de99451ab3c0 22 //----------------------------------------------//------------------------------
gatedClock 3:de99451ab3c0 23 void mmSPI::allocations(void) // object allocations.
gatedClock 3:de99451ab3c0 24 {
gatedClock 3:de99451ab3c0 25 pMOSI = new DigitalOut(mmSPI_MOSI); // SPI MOSI pin object.
gatedClock 3:de99451ab3c0 26 if (!pMOSI) error("\n\r mmSPI::allocations : FATAL malloc error for pMOSI. \n\r");
gatedClock 3:de99451ab3c0 27
gatedClock 3:de99451ab3c0 28 pMISO = new DigitalOut(mmSPI_MISO); // SPI MISO pin object.
gatedClock 3:de99451ab3c0 29 if (!pMISO) error("\n\r mmSPI::allocations : FATAL malloc error for pMISO. \n\r");
gatedClock 3:de99451ab3c0 30
gatedClock 3:de99451ab3c0 31 pSCLK = new DigitalOut(mmSPI_SCLK); // SPI SCLK pin object.
gatedClock 3:de99451ab3c0 32 if (!pSCLK) error("\n\r mmSPI::allocations : FATAL malloc error for pSCLK. \n\r");
gatedClock 3:de99451ab3c0 33 }
gatedClock 4:aa1fe8707bef 34 //----------------------------------------------//------------------------------
gatedClock 4:aa1fe8707bef 35 void mmSPI::setSPIfrequency(float fFreq) // set SPI clock frequency.
gatedClock 4:aa1fe8707bef 36 {
gatedClock 4:aa1fe8707bef 37 fSPIfreq = fFreq; // promote to object scope.
gatedClock 4:aa1fe8707bef 38 if (fSPIfreq < .05) // don't get near divide-by-zero.
gatedClock 4:aa1fe8707bef 39 error("\n\r mmSPI::setSPIfrequency : FATAL SPI frequency set too low. \n\r");
gatedClock 4:aa1fe8707bef 40 fSPIquarterP = (1 / fSPIfreq) / 4; // figure quarter-cycle period.
gatedClock 4:aa1fe8707bef 41 }
gatedClock 4:aa1fe8707bef 42
gatedClock 0:fb42c5acf810 43 //----------------------------------------------//------------------------------
gatedClock 1:15706d15d123 44 char mmSPI::transceive_byte(char cSend) // send/receive a byte.
gatedClock 1:15706d15d123 45 {
gatedClock 2:bebcf53b72dc 46 *pSCLK = 1;
gatedClock 1:15706d15d123 47
gatedClock 1:15706d15d123 48
gatedClock 1:15706d15d123 49
gatedClock 1:15706d15d123 50 }
gatedClock 1:15706d15d123 51 //----------------------------------------------//------------------------------