SPI library used to communicate with an altera development board attached to four zigbee-header pins.
mmSPI.h@31:ea7b25e494b5, 2013-08-25 (annotated)
- Committer:
- gatedClock
- Date:
- Sun Aug 25 20:12:32 2013 +0000
- Revision:
- 31:ea7b25e494b5
- Parent:
- 30:331c7c7d8bc1
- Child:
- 32:5a5d9525c6c4
this is working with python 'run'.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gatedClock | 2:bebcf53b72dc | 1 | #ifndef mmSPI_H // include guard. |
gatedClock | 2:bebcf53b72dc | 2 | #define mmSPI_H // include guard. |
gatedClock | 0:fb42c5acf810 | 3 | /*----------------------------------------------//------------------------------ |
gatedClock | 0:fb42c5acf810 | 4 | student : m-moore |
gatedClock | 0:fb42c5acf810 | 5 | class : external SPI interface |
gatedClock | 0:fb42c5acf810 | 6 | directory : mmSPI |
gatedClock | 0:fb42c5acf810 | 7 | file : mmSPI.h |
gatedClock | 1:15706d15d123 | 8 | ----description---------------------------------//------------------------------ |
gatedClock | 1:15706d15d123 | 9 | ----notes---------------------------------------//------------------------------ |
gatedClock | 1:15706d15d123 | 10 | 1. the SPI interface pins are routed to the zigbee header. |
gatedClock | 0:fb42c5acf810 | 11 | ------------------------------------------------//----------------------------*/ |
gatedClock | 0:fb42c5acf810 | 12 | #include "mbed.h" // standard mbed.org class. |
gatedClock | 15:d6cc57c4e23d | 13 | #include "C12832_lcd.h" // LCD. |
gatedClock | 1:15706d15d123 | 14 | //---defines------------------------------------//------------------------------ |
gatedClock | 8:e2d8bbc3e659 | 15 | #define mmSPI_MOSI p29 // SPI interface pin. |
gatedClock | 8:e2d8bbc3e659 | 16 | #define mmSPI_MISO p30 // SPI interface pin. |
gatedClock | 8:e2d8bbc3e659 | 17 | #define mmSPI_SCLK p9 // SPI interface pin. |
gatedClock | 8:e2d8bbc3e659 | 18 | #define mmCPU_CLK p10 // soft CPU system clock. |
gatedClock | 0:fb42c5acf810 | 19 | /*----------------------------------------------//------------------------------ |
gatedClock | 0:fb42c5acf810 | 20 | ------------------------------------------------//----------------------------*/ |
gatedClock | 2:bebcf53b72dc | 21 | |
gatedClock | 0:fb42c5acf810 | 22 | //==============================================//============================== |
gatedClock | 0:fb42c5acf810 | 23 | class mmSPI |
gatedClock | 0:fb42c5acf810 | 24 | { |
gatedClock | 0:fb42c5acf810 | 25 | public: |
gatedClock | 0:fb42c5acf810 | 26 | mmSPI(); // constructor. |
gatedClock | 0:fb42c5acf810 | 27 | ~mmSPI(); // destructor. |
gatedClock | 3:de99451ab3c0 | 28 | void allocations(); // object allocations. |
gatedClock | 24:d3b8c68f41f2 | 29 | void setSPIfrequency (float); // initializations. |
gatedClock | 24:d3b8c68f41f2 | 30 | void setSendBuffer (char * pcSendBuffer); |
gatedClock | 24:d3b8c68f41f2 | 31 | void setReceiveBuffer(char * pcReceiveBuffer); |
gatedClock | 24:d3b8c68f41f2 | 32 | void setNumberOfBytes(int dNumberOfBytes); |
gatedClock | 21:e90dd0f8aaa1 | 33 | |
gatedClock | 31:ea7b25e494b5 | 34 | // SPI transceive loop. |
gatedClock | 31:ea7b25e494b5 | 35 | void transceive_vector(char cPreCPU, char cPreSPI, char cScan, char cPostCPU); |
gatedClock | 16:0e422fd263c6 | 36 | |
gatedClock | 24:d3b8c68f41f2 | 37 | // write/read CPU registers. |
gatedClock | 23:dbd89a56716d | 38 | void write_register(char cRegister, char cValue); |
gatedClock | 24:d3b8c68f41f2 | 39 | char read_register (char cRegister); |
gatedClock | 24:d3b8c68f41f2 | 40 | // write/read CPU main-memory. |
gatedClock | 24:d3b8c68f41f2 | 41 | void write_memory(char cHData, char cLdata, char cAddress); |
gatedClock | 24:d3b8c68f41f2 | 42 | unsigned int read_memory (char cAddress); |
gatedClock | 22:7524dee5c753 | 43 | |
gatedClock | 30:331c7c7d8bc1 | 44 | void step(); // step the CPU. |
gatedClock | 30:331c7c7d8bc1 | 45 | |
gatedClock | 24:d3b8c68f41f2 | 46 | void clear_transmit_vector(); // fill with 0. |
gatedClock | 24:d3b8c68f41f2 | 47 | |
gatedClock | 0:fb42c5acf810 | 48 | private: |
gatedClock | 2:bebcf53b72dc | 49 | |
gatedClock | 3:de99451ab3c0 | 50 | DigitalOut * pMOSI; // SPI pin. |
gatedClock | 3:de99451ab3c0 | 51 | DigitalOut * pMISO; // SPI pin. |
gatedClock | 3:de99451ab3c0 | 52 | DigitalOut * pSCLK; // SPI pin. |
gatedClock | 8:e2d8bbc3e659 | 53 | DigitalOut * pCPUclk; // soft cpu clock. |
gatedClock | 22:7524dee5c753 | 54 | char * pcSend; // SPI transmit vector. |
gatedClock | 22:7524dee5c753 | 55 | char * pcReceive; // SPI receive vector. |
gatedClock | 4:aa1fe8707bef | 56 | float fSPIfreq; // SPI clock frequency. |
gatedClock | 4:aa1fe8707bef | 57 | float fSPIquarterP; // SPI quarter period. |
gatedClock | 22:7524dee5c753 | 58 | int dNumBytes; // number of SPI bytes. |
gatedClock | 12:a1b7ce9c1d64 | 59 | int dLoop01; // loop index. |
gatedClock | 12:a1b7ce9c1d64 | 60 | int dLoop02; // loop index. |
gatedClock | 0:fb42c5acf810 | 61 | }; |
gatedClock | 2:bebcf53b72dc | 62 | //----------------------------------------------//------------------------------ |
gatedClock | 2:bebcf53b72dc | 63 | #endif // include guard. |