![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
SPI.cpp@53:71f59e195f06, 2018-05-07 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon May 07 15:44:34 2018 +0000
- Revision:
- 53:71f59e195f06
- Child:
- 56:bc5345bc6650
To test version of code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 53:71f59e195f06 | 1 | #include "SPI.hpp" |
thomasmorris | 53:71f59e195f06 | 2 | //File for SPI communication |
thomasmorris | 53:71f59e195f06 | 3 | |
thomasmorris | 53:71f59e195f06 | 4 | |
thomasmorris | 53:71f59e195f06 | 5 | |
thomasmorris | 53:71f59e195f06 | 6 | void SPI_INIT() |
thomasmorris | 53:71f59e195f06 | 7 | { |
thomasmorris | 53:71f59e195f06 | 8 | |
thomasmorris | 53:71f59e195f06 | 9 | |
thomasmorris | 53:71f59e195f06 | 10 | /* |
thomasmorris | 53:71f59e195f06 | 11 | MOSI = Blue |
thomasmorris | 53:71f59e195f06 | 12 | MISO = White |
thomasmorris | 53:71f59e195f06 | 13 | SCLK = Yellow |
thomasmorris | 53:71f59e195f06 | 14 | Slave Select = Green |
thomasmorris | 53:71f59e195f06 | 15 | |
thomasmorris | 53:71f59e195f06 | 16 | */ |
thomasmorris | 53:71f59e195f06 | 17 | |
thomasmorris | 53:71f59e195f06 | 18 | |
thomasmorris | 53:71f59e195f06 | 19 | // Chip must be deselected |
thomasmorris | 53:71f59e195f06 | 20 | cs = 1; //Active Low |
thomasmorris | 53:71f59e195f06 | 21 | |
thomasmorris | 53:71f59e195f06 | 22 | // Setup the spi for 8 bit data, high steady state clock, |
thomasmorris | 53:71f59e195f06 | 23 | // second edge capture, with a 1MHz clock rate |
thomasmorris | 53:71f59e195f06 | 24 | spi.format(16,0); // 8 Data bits phase 0 polarity 0 |
thomasmorris | 53:71f59e195f06 | 25 | spi.frequency(1000000);//Output clock frequency 1Mhz |
thomasmorris | 53:71f59e195f06 | 26 | |
thomasmorris | 53:71f59e195f06 | 27 | // Select the device by seting chip select low |
thomasmorris | 53:71f59e195f06 | 28 | //cs = 0;//This is active after spi is set up |
thomasmorris | 53:71f59e195f06 | 29 | |
thomasmorris | 53:71f59e195f06 | 30 | // Send 0x8f, the command to read the WHOAMI register |
thomasmorris | 53:71f59e195f06 | 31 | //spi.write(0x8F); |
thomasmorris | 53:71f59e195f06 | 32 | |
thomasmorris | 53:71f59e195f06 | 33 | // Send a dummy byte to receive the contents of the WHOAMI register |
thomasmorris | 53:71f59e195f06 | 34 | //int whoami = spi.write(0x00); |
thomasmorris | 53:71f59e195f06 | 35 | //printf("WHOAMI register = 0x%X\n", whoami); |
thomasmorris | 53:71f59e195f06 | 36 | // Deselect the device |
thomasmorris | 53:71f59e195f06 | 37 | //cs = 1; |
thomasmorris | 53:71f59e195f06 | 38 | } |