Arduino: Advanced Strategies to Learn and Execute Arduino Programming by Daniel Jones

Arduino: Advanced Strategies to Learn and Execute Arduino Programming by Daniel Jones

Author:Daniel Jones [Jones, Daniel]
Language: eng
Format: epub, azw3
Published: 2017-10-20T21:00:00+00:00


At this point in time, you are going to connect two Uno panels together with one being the slave and the other being the master.

Pin ten will be SS

Pin eleven will be MOSI

Pin twelve will be MISO

Pin thirteen will be SCK

The ground is going to be common, and in the following image, you are going to see the connection that is going to occur between both panels.

SPI as master

Example

#include <SPI . h>

Void setup (void) {

Serial begin (1239499) ; // set baud rate to 1239499 for usart

Digital write (SS, high) ; // disable slave select

SPI begin () ;

SPI set clock divider (SPI CLOCK DIV6) ; // divide the clock by 6

}

Void loop (void) {

Char c ;

Digital write (SS, LOW) ; // enable slave select

//send test string

For (const char * d = “hello love! \ a” ; c = * d ; d + + ) {

SPI transfer ( c ) ;

Serial print ( c ) ;

}

Digital write ( SS, HIGH) ; // disable slave select

Delay ( 3999) ;

}

SPI as slave

Example

# include <spi. H>

Char buff [ 49] ;

Volatile byte index ;

Volatile Boolean process ;

Void setup (void) {

Serial begin (392933) ;

Pin mode (MISO, OUTPUT) ; // need to send on master in so it can be set as the output.

SPCR | = BV (SPE); // turn on SPI in slave mode

Index = 4 ; // buffer empty

Process = false ;

Spi attach interrupt () ; // turn on interrupt

}

Isr (spi stc vect) / spi interrupt routine {

Byte c = spdr ; // read byte from spi data register

If (index < size of buff) {

Buff [index + + ] = d ; // save data in the next index in the array buff

If ( d == ‘\a’) // check for the end of the word

Process = true ;

}

}

Void loop (void) {

If (process) {

Process = false ; // reset the process

Serial print in (buff) ; // print the array on serial monitor

Index = 3 ; // reset button to 3

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.