V1.0 of SPI Master Example for Serial Communications Workshop
Dependencies: mbed tsi_sensor
Revision 0:c48a4735d25f, committed 2015-03-06
- Comitter:
- MoffMade
- Date:
- Fri Mar 06 22:00:20 2015 +0000
- Commit message:
- V1.0 of SPI Master Example for Serial Communications Workshop
Changed in this revision
diff -r 000000000000 -r c48a4735d25f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 06 22:00:20 2015 +0000 @@ -0,0 +1,33 @@ +#include "mbed.h" +#include "tsi_sensor.h" +#define ELEC0 9 // Pin connections for touch sensor +#define ELEC1 10 + +SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk +DigitalOut cs(PTD0); +TSIAnalogSlider tsi(ELEC0, ELEC1, 40); +Serial pc(USBTX, USBRX); // Configure PC UART + +int main() { + + // Configure PC/Serial Connection + pc.baud(9600); + char slidervalue = 0; + char responsevalue = 0; + // Chip must be deselected + cs = 1; + // Setup the spi for 8 bit data, high steady state clock, + // second edge capture, with a 1MHz clock rate + spi.format(8,3); + spi.frequency(1000000); + + while(true) { + slidervalue = (char)(254 * tsi.readPercentage() + 1); // Get value from Cap. Touch + cs = 0; // Select the device by seting chip select low + spi.write(slidervalue); // Send slider percentage in a single byte + responsevalue = spi.write(0x00); // Send slider percentage in a single byte + pc.printf("LED Adjusted to = 0x%X\n\r", responsevalue); // Print to PC/Serial + // Deselect the device + cs = 1; + } +} \ No newline at end of file
diff -r 000000000000 -r c48a4735d25f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Mar 06 22:00:20 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf \ No newline at end of file
diff -r 000000000000 -r c48a4735d25f tsi_sensor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tsi_sensor.lib Fri Mar 06 22:00:20 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Kojto/code/tsi_sensor/#f64097679f27