test

Dependencies:   mbed

Fork of SPI_master_mdot by Erick

Committer:
gomezerick
Date:
Fri Jun 10 05:19:39 2016 +0000
Revision:
0:bd27ff0337e4
Child:
1:d34b1023e89b
SPI master mdot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gomezerick 0:bd27ff0337e4 1 #include "mbed.h"
gomezerick 0:bd27ff0337e4 2
gomezerick 0:bd27ff0337e4 3 SPI spimaster(SPI1_MOSI, SPI1_MISO, SPI1_SCK);
gomezerick 0:bd27ff0337e4 4 DigitalOut cs(SPI1_CS);
gomezerick 0:bd27ff0337e4 5
gomezerick 0:bd27ff0337e4 6 int main()
gomezerick 0:bd27ff0337e4 7 {
gomezerick 0:bd27ff0337e4 8 int response;
gomezerick 0:bd27ff0337e4 9 // Chip must be deselected
gomezerick 0:bd27ff0337e4 10 cs = 1;
gomezerick 0:bd27ff0337e4 11
gomezerick 0:bd27ff0337e4 12 // Setup the spi for 8 bit data, high steady state clock,
gomezerick 0:bd27ff0337e4 13 // second edge capture, with a 1MHz clock rate
gomezerick 0:bd27ff0337e4 14 spimaster.format(8,0);
gomezerick 0:bd27ff0337e4 15 spimaster.frequency(1000000);
gomezerick 0:bd27ff0337e4 16 while(true)
gomezerick 0:bd27ff0337e4 17 {
gomezerick 0:bd27ff0337e4 18 // Select the device by seting chip select low
gomezerick 0:bd27ff0337e4 19 cs = 0;
gomezerick 0:bd27ff0337e4 20
gomezerick 0:bd27ff0337e4 21 // Send a dummy byte to receive response from the slave
gomezerick 0:bd27ff0337e4 22 response = spimaster.write(0x00);
gomezerick 0:bd27ff0337e4 23 printf("\r\nSlave response = 0x%X", response);
gomezerick 0:bd27ff0337e4 24
gomezerick 0:bd27ff0337e4 25 // Deselect the device
gomezerick 0:bd27ff0337e4 26 cs = 1;
gomezerick 0:bd27ff0337e4 27 wait(1);
gomezerick 0:bd27ff0337e4 28 }
gomezerick 0:bd27ff0337e4 29 }