/arduino-spi

Generalized easy to use SPI library for Arduino designed mainly for immense data transfer through multiple slaves. This library features Cyclic Redundancy Check (CRC) and user defined data transfer which inspired by Nick Gammon.

Primary LanguageC++

SPI Master and Slave Library

Github stars Open in Visual Studio Code Build with PlatformIO PRs Welcome

If you don't have VS Code you can install from here. After downloading click extensions and type and install PlatformIO IDE. Then select your arduino board and upload. Source codes have to be located in /src folder, so if you want to upload slave code then move master.cpp to /test and slave.cpp back to /src folder. Libraries are located in /lib.

For demonstrating purpose it could have multiple slaves, but it is okay that all the slaves have the same code.

Usage for Master

Master master; // creating Master type variable.
master.setup(SLAVE_PIN); // setup the master. 
master.setCurrentAngle(7); // set the currentAngle variable.
master.setMotorID(8);      // set the motorID variable.
master.setTargetAngle(9);  // set the targetAngle variable.
master.enable(SLAVE_PIN); // opening the slave for transmission.
master.write(SLAVE_PIN); // sending the data from bus.
master.disable(SLAVE_PIN); // closing the slave for transmission.

Usage for Slave

Slave slave; // creating Slave type variable.
slave.setup(); // setup the slave.
slave.read(slave); // reading the data from bus.