v2

Dependencies:   mbed

spi_master.cpp

Committer:
Yanagihara
Date:
2021-01-07
Revision:
2:6d9572f5523e
Parent:
1:5a1355e57aed
Child:
3:894278e5d918

File content as of revision 2:6d9572f5523e:

#include "mbed.h"

SPI to_eps(p5,p6,p7);
DigitalOut cs(p8);

Serial pc(USBTX,USBRX);

#define DTIME 0.1

int main()
{
    pc.printf("--Hi,this is cdh(master).\r\n");
    cs = 1;

    to_eps.format(8,3);
    to_eps.frequency(1000000);
    int cmd = 0;

    while(1) {
        char c = pc.getc();
        pc.printf("count: %d, ",cmd);

        cs=0;
        int dummy = to_eps.write(cmd); // send command
        cs=1;
        
        pc.printf("dummy: %x, ",dummy);
                 
        if(cmd == 1){        
        wait(1);
        cs=0;
        int rdata = to_eps.write(0x00);       
        cs=1;
        pc.printf("rdata: %x\r\n",rdata);
        }
        
        if(cmd == 2){        
        wait(3);
        cs=0;
        int rdata1 = to_eps.write(0x00);
        int rdata2 = to_eps.write(0x00);       
        cs=1;
        pc.printf("rdata1: %x\r\n",rdata1);
        pc.printf("rdata2: %x\r\n",rdata2);
        }
        
        cmd++;
    }
}