Alexander Entinger / Mbed OS spi-slave-echo
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* This demo code is intended to test SPI slave
00002  * functionality on STM32 DISCO-L072CZ-LRWAN1
00003  */
00004 
00005 #include "mbed.h"
00006 
00007 #define SLAVE_MOSI  (PB_15)
00008 #define SLAVE_MISO  (PB_14)
00009 #define SLAVE_SCLK  (PB_13)
00010 #define SLAVE_SSEL  (PB_12)
00011 
00012 
00013 SPISlave spi_slave(SLAVE_MOSI,
00014                    SLAVE_MISO,
00015                    SLAVE_SCLK,
00016                    SLAVE_SSEL);
00017  
00018 int main()
00019 {
00020     spi_slave.reply(0);
00021     
00022     for(;;) {
00023         if(spi_slave.receive()) {
00024             spi_slave.reply(spi_slave.read());
00025         }    
00026     }
00027 }