SPI library used to communicate with an altera development board attached to four zigbee-header pins.
Diff: mmSPI.cpp
- Revision:
- 22:7524dee5c753
- Parent:
- 21:e90dd0f8aaa1
- Child:
- 23:dbd89a56716d
--- a/mmSPI.cpp Tue Aug 20 14:02:56 2013 +0000 +++ b/mmSPI.cpp Tue Aug 20 14:13:32 2013 +0000 @@ -49,11 +49,33 @@ error("\n\r mmSPI::setSPIfrequency : FATAL SPI frequency set too low. \n\r"); fSPIquarterP = (1 / fSPIfreq) / 4; // figure quarter-cycle period. } +//----------------------------------------------//------------------------------ + // obtain SPI send buffer pointer. + void mmSPI::setSendBuffer(char * pcSendBuffer) + { + pcSend = pcSendBuffer; // promote to object scope. + } +//----------------------------------------------//------------------------------ + // obtain SPI receive buffer pointer. + void mmSPI::setReceiveBuffer(char * pcReceiveBuffer) + { + pcReceive = pcReceiveBuffer; // promote to object scope. + } //----------------------------------------------//------------------------------ + // obtain number of SPI bytes. + void mmSPI::setNumberOfBytes(int dNumberOfBytes) + { + dNumBytes = dNumberOfBytes; // promote to object scope. + } +//----------------------------------------------//------------------------------ + + + + // transceive a character array. // limit is 256 characters. // MSB out/in first. - void mmSPI::transceive_vector2(char *pcReceive, char *pcSend, int dNumBytes) + void mmSPI::transceive_vector(char *pcReceive, char *pcSend, int dNumBytes) { int dClear; int dIndex; @@ -118,7 +140,7 @@ pcSend[1] = ((cRegister & 0x07) << 2) | 0xA0; pcSend[0] = cValue & 0xFF; // immediate value to i.w. - transceive_vector2(pcReceive, pcSend, 8); // transmit command. + transceive_vector(pcReceive, pcSend, 8); // transmit command. // clear transmit vector. for (dLoop = 0; dLoop < 8; dLoop++) pcSend[dLoop] = 0x00; @@ -134,7 +156,7 @@ // send all 0. for (dLoop = 0; dLoop < 8; dLoop++) pcSend[dLoop] = 0x00; - transceive_vector2(pcReceive, pcSend, 8); // snap & scan-out reg contents. + transceive_vector(pcReceive, pcSend, 8); // snap & scan-out reg contents. return (pcReceive[6 - cRegister]); // return the particular reg value. } @@ -156,12 +178,12 @@ pcSend[7] = 0x00; // write-enable high. pcSend[1] = 0x02; pcSend[0] = 0x00; - transceive_vector2(pcReceive, pcSend, 8); + transceive_vector(pcReceive, pcSend, 8); pcSend[7] = 0x00; // write-enable low. pcSend[1] = 0x00; pcSend[0] = 0x00; - transceive_vector2(pcReceive, pcSend, 8); + transceive_vector(pcReceive, pcSend, 8); // clear transmit vector. for (dLoop = 0; dLoop < 8; dLoop++) pcSend[dLoop] = 0x00; @@ -186,12 +208,12 @@ pcSend[7] = 0x02; // mbed sends command. pcSend[1] = 0xC8; // R2 <- MM[R3] pcSend[0] = 0x00; - transceive_vector2(pcReceive, pcSend, 8); // send command. + transceive_vector(pcReceive, pcSend, 8); // send command. pcSend[7] = 0x02; // mbed sends command. pcSend[1] = 0xC4; // R1 <- MM[R3] pcSend[0] = 0x00; - transceive_vector2(pcReceive, pcSend, 8); // send command. + transceive_vector(pcReceive, pcSend, 8); // send command. // obtain MM content. cHData = read_register(0x02, pcReceive, pcSend);