TheMartian
Junior Member level 3
Hey
I am stuck with Memory project.
I can read memory ID so SPI communication works.
But when I write a byte and read it back, it comes back invalid.
My code:
I assume that SPI works because "read memory ID" command returns correct values, compared to the ones with Datasheet.
But read always returns the same value and I don't know where the problem is. It might be in write, it might be in read.
I am using PIC18.
I checked SPI read/write order with Datasheet and it's OK:
Any suggestions what might be wrong?
I am stuck with Memory project.
I can read memory ID so SPI communication works.
But when I write a byte and read it back, it comes back invalid.
My code:
Code:
void SST25VF_writeByte(uint32_t adr, uint8_t dat)
{
//dat = 'A';
SPI_INIT
setFlashSSN(LOW);
SPI1_Write(0x06);//write enable instruction
setFlashSSN(HIGH);
Delay_us(1);// nop();
setFlashSSN(LOW);
SPI1_Write(0x02); // Write Byte //
SST25VF_setAddress(adr); // 3 address cycles
SPI1_Write(dat); // data cycle
setFlashSSN(HIGH);
SST25VF_waitUntilDone(); /// waitUntilDone();
}
uint8_t SST25VF_readByte(uint32_t addres)
{
uint8_t retV;
SPI_INIT
setFlashSSN(LOW);
SPI1_Write(0x03); //
SST25VF_setAddress(addres); // 3 bytes
retV = SPI1_Read(0);
setFlashSSN(HIGH);
return retV;
}
I assume that SPI works because "read memory ID" command returns correct values, compared to the ones with Datasheet.
But read always returns the same value and I don't know where the problem is. It might be in write, it might be in read.
I am using PIC18.
I checked SPI read/write order with Datasheet and it's OK:
Any suggestions what might be wrong?