User Tools

Site Tools


arduino:gammon-spi-controller

This is an old revision of the document!


From SPI - Serial Peripheral Interface - for Arduino by Nick Gammon.

gammon-spi-controller.ino
// Written by Nick Gammon
// February 2011
 
 
#include <SPI.h>
 
void setup (void)
{
 
  digitalWrite(SS, HIGH);  // ensure SS stays high for now
 
  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
  SPI.begin ();
 
  // Slow down the master a bit
  SPI.setClockDivider(SPI_CLOCK_DIV8);
 
}  // end of setup
 
 
void loop (void)
{
 
  char c;
 
  // enable Slave Select
  digitalWrite(SS, LOW);    // SS is pin 10
 
  // send test string
  for (const char * p = "Hello, world!\n" ; c = *p; p++)
    SPI.transfer (c);
 
  // disable Slave Select
  digitalWrite(SS, HIGH);
 
  delay (1000);  // 1 seconds delay 
}  // end of loop
arduino/gammon-spi-controller.1690220641.txt.gz · Last modified: 2023/07/24 17:44 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki