/************************************************************************
*
* Test of the Pmod
*
*************************************************************************
* Description: Pmod_DA1
* Outputs A1 and B1 deliver square wave signals in phase opposition
* with a programmable period.
*
* Material
* 1. Arduino Uno
* 2. Pmod DA1
*
************************************************************************/
#define CS 10 // affectation of CS pin
#include <SPI.h> // Include library
int periode=10;
void setup()
{
SPI.begin(); // initialization of SPI port
SPI.setDataMode(SPI_MODE0); // configuration SPI communication in mode 0
SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1MHz
pinMode(CS, OUTPUT);
}
void loop()
{
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(16); // send commande bits (output A active and output B inactive)
SPI.transfer(255); // send data bits
digitalWrite(CS, HIGH); // deactivation CS line
delay(periode/2); // wait
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(12); // send commande bits (output A inactive and output B active)
SPI.transfer(255); // send data bits
digitalWrite(CS, HIGH); // deactivation CS line
delay(periode/2); // wait
}
Comments
Please log in or sign up to comment.