wimbeaumont Project
/
SPIslavetest
removed mbed
Diff: main.cpp
- Revision:
- 0:fdabc5739b6c
- Child:
- 1:2aadc0008662
diff -r 000000000000 -r fdabc5739b6c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jun 24 15:42:58 2019 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" + +DigitalIn spiin(p5); +//SPISlave slave(PTA7,PTA6,PTB0,PTA5); +SPISlave slave(p5,p6,p7,p8); +AnalogIn ain1(p20); +//SPISlave slave(p11,p12,p13,p14); + +Serial pc(USBTX, USBRX); +#define VER "1.34" + +int main() { + spiin.mode(PullUp); + slave.format(8,0); + slave.frequency(1000000); + int v, res,res2; + int cnt=0; + int slvrecnt=0; + + pc.printf(" start spi slave test %s \n\r",VER ); + slave.reply(0); // is in the example ? + float sample=0; + int slavereply; + while(1) { + cnt++; + //if( (cnt % 10000000) ==0) pc.printf("%s loop : cnt %d , slvrsv cnt %d\n\r",VER,cnt, slvrecnt); + sample=200*ain1.read(); + if(slave.receive()) { + v = slave.read(); // Read byte from master + if(v!=0){// discard the dummy buffer write + //res=(v+5); // Add 5 to it + res=slvrecnt%256; + // res=0x13; + slavereply=(int)sample; + slave.reply(slavereply);// Make this the next reply + + //pc.printf("v=%x res= %x\n\r", v,slavereply); + slvrecnt++; + } + else { + res2=cnt%256; + slave.reply(res2); // Make this the next reply + slvrecnt=0; + //pc.printf("v=%d res2 = %x\n\r", v , res2); + } + //pc.printf( "slave receive done \n\r"); + //} + } + } + + +} \ No newline at end of file