/************************************************************************
*
* Test of the Pmod
*
*************************************************************************
* Description: Pmod_SF2
* Data is stored at the specified address and then replayed
* and displayed in the serial monitor.
*
* Material
* 1. Arduino Uno
* 2. Pmod SF2
* 3. Adafruit module TXB0108
*
************************************************************************/
#define CS 10 // Assignment of the CS pin
#include <SPI.h> // call library
int i;
int adresse=0xFF;
int donnee=0x55;
byte recu[3];
byte envoi[5];
void setup()
{
Serial.begin(9600); // initialization of
serial communication
SPI.begin(); // initialization of SPI port
SPI.setDataMode(SPI_MODE0); // configuration of SPI communication in mode 0
SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1MHz
pinMode(CS, OUTPUT);
envoi[0] = adresse >> 16;
envoi[1] = adresse >> 8;
envoi[2] = adresse;
envoi[3] = donnee;
// validation écriture dans la mémoire
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0x06); // write validation
digitalWrite(CS, HIGH); // deactivation of CS line
// effacement complet la mémoire
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0xC7); // erase
digitalWrite(CS, HIGH); // deactivation of CS line
// écriture d'une donnée à l'adresse spécifiée
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0x02); // write data a specified adress
for (i=0;i<4;i=i+1)
{
SPI.transfer(envoi[i]);
}
digitalWrite(CS, HIGH); // deactivation of CS line
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0x04); // lock write
digitalWrite(CS, HIGH); // deactivation of CS line
delay(1000);
}
void loop()
{
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0x03); // read data from adress
for (i=0;i<3;i=i+1)
{
SPI.transfer(envoi[i]);
}
recu[0]=SPI.transfer(0);
digitalWrite(CS, HIGH); // deactivation of CS line
Serial.println(recu[0],HEX);
}
Comments
Please log in or sign up to comment.