Slave used to test FPGA spi master

Dependencies:   mbed

Committer:
leonardoaraujosantos
Date:
Thu Sep 24 07:02:28 2015 +0000
Revision:
0:5fb6d5c13819
Working on slave (With FPGA)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leonardoaraujosantos 0:5fb6d5c13819 1 #include "mbed.h"
leonardoaraujosantos 0:5fb6d5c13819 2 /*
leonardoaraujosantos 0:5fb6d5c13819 3 Gael board NUCLEO-F401RE SPI slave
leonardoaraujosantos 0:5fb6d5c13819 4 */
leonardoaraujosantos 0:5fb6d5c13819 5
leonardoaraujosantos 0:5fb6d5c13819 6 //------------------------------------
leonardoaraujosantos 0:5fb6d5c13819 7 // Serial configuration (Put on hyperterminal or Putty)
leonardoaraujosantos 0:5fb6d5c13819 8 // 115200 bauds, 8-bit data, no parity
leonardoaraujosantos 0:5fb6d5c13819 9 //------------------------------------
leonardoaraujosantos 0:5fb6d5c13819 10 Serial serialIO(SERIAL_TX, SERIAL_RX);
leonardoaraujosantos 0:5fb6d5c13819 11
leonardoaraujosantos 0:5fb6d5c13819 12 int main() {
leonardoaraujosantos 0:5fb6d5c13819 13
leonardoaraujosantos 0:5fb6d5c13819 14 // Configure the serial speed.
leonardoaraujosantos 0:5fb6d5c13819 15 serialIO.baud(115200);
leonardoaraujosantos 0:5fb6d5c13819 16 serialIO.printf("SPI Slave example with mbed!\r\n");
leonardoaraujosantos 0:5fb6d5c13819 17
leonardoaraujosantos 0:5fb6d5c13819 18 // Configure the SPI to 8-bits Mode 0, 5Mhz
leonardoaraujosantos 0:5fb6d5c13819 19 SPISlave spiSlave(PA_7, PA_6, PA_5, PA_15); // mosi, miso, sclk, ssel
leonardoaraujosantos 0:5fb6d5c13819 20 spiSlave.format(8,0);
leonardoaraujosantos 0:5fb6d5c13819 21 spiSlave.frequency(5000000);
leonardoaraujosantos 0:5fb6d5c13819 22 spiSlave.reply(191);
leonardoaraujosantos 0:5fb6d5c13819 23
leonardoaraujosantos 0:5fb6d5c13819 24 serialIO.printf("SPI Slave Waiting!\r\n");
leonardoaraujosantos 0:5fb6d5c13819 25 while(1) {
leonardoaraujosantos 0:5fb6d5c13819 26 wait_us(2);
leonardoaraujosantos 0:5fb6d5c13819 27 if(spiSlave.receive())
leonardoaraujosantos 0:5fb6d5c13819 28 {
leonardoaraujosantos 0:5fb6d5c13819 29 serialIO.printf("Slave received: %d\r\n",spiSlave.read());
leonardoaraujosantos 0:5fb6d5c13819 30 }
leonardoaraujosantos 0:5fb6d5c13819 31 }
leonardoaraujosantos 0:5fb6d5c13819 32 }
leonardoaraujosantos 0:5fb6d5c13819 33