Tsungta Wu / Mbed OS mbed_SPIS_multiByte_example
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //#include "mbed.h"
00002 // 
00003 //SPI spi(A1, A2, A3); // mosi, miso, sclk
00004 //DigitalOut cs(A0);
00005 //
00006 //uint8_t tx_buf[32] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V'};
00007 //
00008 //int main() {
00009 //    // Chip must be deselected
00010 //    cs = 1;
00011 // 
00012 //    // Setup the spi for 8 bit data, high steady state clock,
00013 //    // second edge capture, with a 1MHz clock rate
00014 //    spi.format(8,1);
00015 //    spi.frequency(8000000);
00016 // 
00017 //    // Select the device by seting chip select low
00018 //    cs = 0;
00019 // 
00020 //    for(int i=0; i<32; i++)
00021 //        spi.write(tx_buf[i]);
00022 //    printf("End of transmission \r\n");
00023 //     
00024 //    // Deselect the device
00025 //    cs = 1;
00026 //}
00027 
00028 #include "mbed.h"
00029 
00030 #include "SPISlave_multiByte.h"
00031 SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel
00032 Serial uart(USBTX, USBRX);
00033 
00034 #define TXRX_LENGTH 224  //max is 16
00035 int main() {
00036     uart.printf("START!");
00037     device.format(8,1);    
00038     device.frequency(8000000);
00039     
00040    device.reply((uint8_t*)"xyz", TXRX_LENGTH);
00041    while(1) {
00042        if(device.receive(TXRX_LENGTH)) {
00043            //Thread::wait(1000);
00044            int ret = device.read();   // Read byte from master
00045            uart.printf("ret = %s ", ret);
00046                         
00047        }
00048    }
00049 }