Im using Arduino DUE to read and write blocks, byte and word to a MX25L6406E EEPROM. I followed a sample code online and it didn't recognize SPCR, SPSR and SPDR registers. Here is part of my code:
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte
}
void setup()
{
Serial.begin(9600);
SPI.begin(10);
pinMode(PowerControl, OUTPUT);
digitalWrite(PowerControl, LOW); //Set it LOW to activate 3V based on Shield Schematic
pinMode(RelayCtrl, OUTPUT); //Enable Relay Control
digitalWrite(RelayCtrl, HIGH); //Set HIGH to activate
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,HIGH); //disable device
//SPCR = 01010000
//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
//sample on leading edge of clk,system clock/4 rate (fastest)
SPCR = (1<<SPE)|(1<<MSTR); // SPCR Control Register
clr = SPSR; // SPSR Status Register
clr = SPDR; // SPDR Data Register
The error is below:
Writing_Reading5:47:3: error: 'SPDR' was not declared in this scope
SPDR = data; // Start the transmission
^
Writing_Reading5:48:12: error: 'SPSR' was not declared in this scope
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
^
Writing_Reading5:48:23: error: 'SPIF' was not declared in this scope
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
I did declare the SPI library in the beginning "#include <SPI.h>" What should I do?
Those are the registers used in the 8 bit avr architecture like the AT328.
The Arduino Due is based on the Atmel SAM3X8E ARM Cortex-M3 CPU which is a 32-bit ARM core microcontroller. There is different nomenclature and values for the spi registers on the device.
Please give me an example of writing bytes to MX25L6406E EEPROM using arduino DUE. I doesn't need to be a full code but just this part.... I cant make it work.