Thomas Morris / Mbed OS PROJ324_Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SPI.cpp Source File

SPI.cpp

00001 #include "SPI.hpp"
00002 //File for SPI communication
00003 
00004 //int SPI_RX_DATA = 0;
00005 
00006 void SPI_INIT()
00007 {
00008     
00009     
00010     /*
00011     MOSI = Blue
00012     MISO = White
00013     SCLK = Yellow
00014     Slave Select = Green
00015     
00016     */
00017 
00018  
00019     // Chip must be deselected
00020     cs = 1; //Active Low
00021 
00022     // Setup the spi for 8 bit data, high steady state clock,
00023     // second edge capture, with a 1MHz clock rate
00024     spi.format(16,0); // 8 Data bits phase 0 polarity 0
00025     spi.frequency(1000000);//Output clock frequency 1Mhz
00026  
00027     // Select the device by seting chip select low
00028     //cs = 0;//This is active after spi is set up
00029  
00030     // Send 0x8f, the command to read the WHOAMI register
00031     //spi.write(0x8F);
00032  
00033     // Send a dummy byte to receive the contents of the WHOAMI register
00034     //int whoami = spi.write(0x00);
00035     //printf("WHOAMI register = 0x%X\n", whoami);
00036     // Deselect the device
00037     //cs = 1;
00038 }
00039 
00040 
00041 void SPI_INTERFACE_SERIAL()
00042 {
00043     /*
00044     //pc.printf("SPI Test \n");
00045     Thread::wait(1000);
00046     cs= 0;
00047     SPI_RX_DATA = spi.write(0xF0);
00048     wait_us(3);
00049     cs= 1;
00050     colour_data = SPI_RX_DATA;
00051     if(Log_Value == 1){pc.printf("Received data = %d\n", SPI_RX_DATA);}
00052     pc.printf("Received data = %d\n", SPI_RX_DATA);
00053     Thread::wait(1000); 
00054     */
00055 }