SPI COMMUNICATION USING CLOUDX CloudX

  • img
Project Details

PROJECT DETAILS

This project is all about SPI(Serial Pheripheral Interface) communication on the popular cloudxM663 board making use of its inbuilt library.

The question is why should we bother about SPI or need SPI ??

truely SPI is a communication protocol in electronics which runs synchronously i.e. the sender(MASTER) and the receiver (SLAVE) have to communicate on the same clock and frequency lesser error in communication and so far one of the fastest communication protocols,simple,and reliable as compared to I2C in which bus hanging is a big problem.

to read more about SPI here is a link provided below on wikipedia

https://en.wikipedia.org/wiki/Serial_Peripheral_Interface

After going through the above link 

SCOPE

the scope of this project is that i'll be sending data 0 - 127 from the slave1 to the master and when receives each data , it transfers such data to slave2, then the slave 2 display binary representation of the received data on LED(LIGHT Emitting Diodes). 

1. The reason is to show that master has transmitted to the slave and recieved from the slave

  1. 2. The slave has transmitted and received from the master.

CIRCUIT DIAGRAM

PROJECT MATERIALS 

3 cloudx m633 board 

connecting wires

8 220ohms resistors

10 LED (Light emitting diodes)

CODES

(MASTER)
#include 
#include 

unsigned char readString[5]; 
unsigned char readValue = 0; 

#define slave1 1 
#define slave2 2 

setup(){ 
    
    SPI_init(master); //initializes the SPI for the master device 
       pinMode(slave1, OUTPUT); 
    pinMode(slave2, OUTPUT); 
    digitalWrite(slave1, HIGH); 
    digitalWrite(slave2, HIGH); 
     
loop(){ 
        //---------------------------------------------- 
       //Here, the master device enables slave1 device, 
       //(ie. by sending a LOW to its SS-pin), in order  
       //to read from it. 
       //---------------------------------------------- 
       digitalWrite(slave1, LOW);  
       digitalWrite(slave2, HIGH); 
        readValue= SPI_read(); 
       //---------------------------------------------- 
       //Here, the master device enables slave2 device, 
       //(and disables slave1), in order to write to it. 
       //---------------------------------------------- 
       digitalWrite(slave1, HIGH);  
       digitalWrite(slave2, LOW); 
       SPI_write(readValue); 
        
       delayMs(1000); 
   } 
}

 

( SLAVE1)

#include 
#include 


setup(){ 

   SPI_init(slave);  //initializes the SPI for the slave device 
    
    loop(){ 
        
       //---------------------------------------------- 
       //This routine continuously sends numerical data  
       //-ranging from 0 to 127, to the master device.  
       //---------------------------------------------- 
       for(byte g=0; g<=127; g++) { 
           SPI_write(g); 
           delayMs(1000); 
       } 
  } 
}

(SLAVE2)


#include 
#include 

 int receivedValue; 
setup(){ 
   SPI_init(slave);  //initializes the SPI for the slave device  
   portMode(2, 0x00);      //sets all port2 pins as output   
   portWrite(2, OFF_ALL);  //initializes them to 0 (ie. switching them all off)     
   loop(){       
       //------------------------------------------------------- 
       //This routine continuously reads from the master device,  
       //and outputs the contents on the pins.   
       //------------------------------------------------------- 
       receivedValue = SPI_read(); 
       //    portWrite(2, receivedValue); 
     } 

APPLICATION

Most advanced devices makes use of SPI such as, Ethernet communications, Graphic displays, robotics , etc.

 

OUTPUT

Share this with friends