Hi guys/gals,
I'm trying to read/write 32 bit long values to a Micron M25P16 using the SPI Arduino library. As I understand it you can only transfer/receive 8 bits of information at a given time using SPI.transfer().
I'm using a 328 arduino pro mini. I have been successful reading and writing 1 byte of data. But when it comes to a long or float I somehow can't manage to capture or drive the the full 4 byte transmission.
Here is a sample of confirmed working code that will work with a 1 byte write.
void WriteByte() {
digitalWrite(slaveSelect,LOW);
SPI.transfer(pageProgram); //op command for a write command
int address = 3;
SPI.transfer(address >> 16); //page program needs the address to be sent as a 3 byte address MSB
SPI.transfer(address >> 8);
SPI.transfer(address);
SPI.transfer(0b01111111); // takes 1 data byte, decimal 127
digitalWrite(slaveSelect,HIGH);
delay(1000); //write buffer
}
So basically the question is how would I capture or transmit a 32 bit value? my thoughts are something like this but this is just returning a 0 value when I try to perform a read.
float buffer [10] = {70.2, -24.5, 100.23, 10, 65326, 2};
void WriteDataBytes(uint32_t epromStartAddress) {
digitalWrite(chipSelect, LOW);
SPI.transfer(pageProgram);
SPI.transfer(epromStartAddress >> 16); //address to be sent as a 3 byte address MSB
SPI.transfer(epromStartAddress >> 8);
SPI.transfer(epromStartAddress);
for (int I = 0; I < 8; I++) {
SPI.transfer(buffer >> 24);
_ SPI.transfer(buffer >> 16);_
_ SPI.transfer(buffer >> 8);
* SPI.transfer(buffer[0]);
}
digitalWrite(chipSelect, HIGH);
delay(100);
}
I have attached the EPROM spec but my inclination is that the fault lies with how I use SPI.transfer()._
M25P16_OnBoardFlash16Mb.pdf (614 KB)*