I am attempting to communicate with a 25LC256 serial (SPI) EEPROM with a
18F4520. I have successfully communicated with this same EEPROM with a 18F4431 using the same code.The code I am using is as follows:
MEM_CS = 0;
SSPBUF = 0x02; while(SSPSTATbits.BF != 1); SSPBUF = AddressHigh; while(SSPSTATbits.BF != 1); SSPBUF = AddressLow; while(SSPSTATbits.BF != 1); SSPBUF = DataByte; while(SSPSTATbits.BF != 1);
MEM_CS = 1;
I have connected a scope on the SDO line of the microcontroller. I see the
0x06 clocked out followed by 3 zeros...no matter what the values of AddressHigh, AddressLow, and DataByte are. I notice from the In-Circuit Debugger that after this transfer, the collision bit gets set somewhere. I have tried replacing the 3 variables with fixed values and everything works fine (the correct fixed values are transmitted from the SDO pin).I see in the dissassembly listing that the "SSPBUF = AddressHigh" instruction is represented using...
MOVFF {SSPBUF}, {AddressHigh} NOP
where the brackets represent the address of SSPBUF and AddressHigh.
Am I missing something here? Is this a problem with the microcontroller itself or with the compiler? I have ruled out a connection problem because everything works fine when using fixed values.
Thanks!