This code acts as the master controlling the slave actions, done using FRDM_KL_25Z

Dependencies:   mbed

main.cpp

Committer:
suhasini
Date:
2016-07-29
Revision:
0:7478eb44f4b1

File content as of revision 0:7478eb44f4b1:

#include "mbed.h"
 
SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
DigitalOut cs(PTD0);
Serial pc(USBTX,USBRX);

 
int main() {
    pc.baud(115200);
    // Chip must be deselected
    cs = 1;

    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    spi.format(8,1);
    //spi.frequency(1000000);
    spi.frequency(512000); //internal clock frequency of ADS1291
 
    // Select the device by setting chip select low
    cs = 0;
 int v=0;
    // Send 0x8f, the command to read the WHOAMI register
    spi.write(0x8F);


    // Send a dummy byte to receive the contents of the WHOAMI register
    int whoami = spi.write(0x00);
  //  printf("WHOAMI register = 0x%X\n", whoami);
  while(1)
  {
      wait(1);
      
  spi.write(v);
   pc.printf("read the data %d",v);
  //led = !led;
  if(v==255)
  v=0;
  else
  v=v+1;
}
    // Deselect the device
    cs = 1;
}