SPI Slave Recieve 16bit Test.

Dependencies:   mbed-rtos mbed

Fork of Nucleo_rtos_SPISlave_Test by Ryo Od

main.cpp

Committer:
ryood
Date:
2016-09-27
Revision:
0:4cc5b11f7d91
Child:
1:ba17cd3b6ecf

File content as of revision 0:4cc5b11f7d91:

#include "mbed.h"
#include "rtos.h"
#include "SPISlave.h"

#define SPI_SPEED   (10000000)

BusOut Leds(PA_10, PB_3, PB_5, PB_4, PB_10, PA_8);

SPISlave SpiS(PA_7, PA_6, PA_5, PA_4);    // mosi, miso, sclk, ssel

int main()
{
    printf("\r\n\nNucleo rtos SPISlave Test..\r\n");
    
    for (int i = 0; i < 5; i++) {
        Leds.write(0x3f);
        Thread::wait(100);
        Leds.write(0x00);
        Thread::wait(100);
    }

    SpiS.format(8, 0);
    SpiS.frequency(SPI_SPEED);

    unsigned int count = 0;
    SpiS.reply(0);
    while(1) {
        if(SpiS.receive()) {
            int v = SpiS.read();   // Read byte from master
            Leds.write(v);
            SpiS.reply(count % 16);
            count++;
        }
    }
}