User Tools

Site Tools


arduino:gammon-spi-controller

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
arduino:gammon-spi-controller [2023/07/24 17:43] mithatarduino:gammon-spi-controller [2023/07/24 18:43] (current) mithat
Line 1: Line 1:
 +From [[http://www.gammon.com.au/spi|SPI - Serial Peripheral Interface - for Arduino]] by Nick Gammon. Modified to use the newish and preferred ''SPI.beginTransaction()'' and ''SPI.endTransaction()''.
 +
 +<file cpp gammon-spi-controller.ino>
 // Written by Nick Gammon // Written by Nick Gammon
 // February 2011 // February 2011
Line 16: Line 19:
  
   // Slow down the master a bit   // Slow down the master a bit
-//  SPI.setClockDivider(SPI_CLOCK_DIV8);  // mithat: let'go full speed+//  SPI.setClockDivider(SPI_CLOCK_DIV8);  // mithat: let'do this the preferred way
      
 }  // end of setup }  // end of setup
Line 25: Line 28:
  
   char c;   char c;
 +
 +  SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));  // mithat: this is the preferred way
  
   // enable Slave Select   // enable Slave Select
Line 30: Line 35:
  
   // send test string   // send test string
-  for (const char * p = "Hello, world!\n" ; c = *p; p++)+  for (const char * p = "Hello, world!\n"(c = *p); p++)
   {   {
     SPI.transfer (c);     SPI.transfer (c);
-    delayMicroseconds(5);    // mithat: added small delay to make things work at full speed+    delayMicroseconds(5);    // mithat: added small delay to make things work at given speed
   }   }
  
   // disable Slave Select   // disable Slave Select
   digitalWrite(SS, HIGH);   digitalWrite(SS, HIGH);
 +  SPI.endTransaction();      // mithat: finish preferred way
  
   delay (1000);  // 1 seconds delay    delay (1000);  // 1 seconds delay 
 }  // end of loop }  // end of loop
 </file> </file>
arduino/gammon-spi-controller.1690220589.txt.gz · Last modified: 2023/07/24 17:43 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki