OK, after a lot of trial and error and finally getting a scope to look at some signals I determined what was going on. In the code below I found that I have to put a small delay (Pauseus 25) after each While SSPSTAT.0 = 0: Wend statement. Also had to put some delay between the WRITE ENABLE sequence and the next WRITE sequence. Also found that I can't go immediately from a WRITE into a READ without some delay between.
Code:Write_SPI_Data: Gosub Write_Enable Low CS SSPBUF = %00000010 ' Send Opcode for WRITE sequence While SSPSTAT.0 = 0: Wend ' Wait for completion dummy_data = SSPBUF SSPBUF = %00000000 ' Send MSByte of EEPROM address While SSPSTAT.0 = 0: Wend ' Wait for completion dummy_data = SSPBUF SSPBUF = %00000000 ' Send Middle Byte of EEPROM address While SSPSTAT.0 = 0: Wend ' Wait for completion dummy_data = SSPBUF SSPBUF = %00000000 ' Send LSByte of EEPROM address While SSPSTAT.0 = 0: Wend ' Wait for completion dummy_data = SSPBUF SSPBUF = %00000111 ' Send data byte While SSPSTAT.0 = 0: Wend ' Wait for completion dummy_data = SSPBUF High CS




Bookmarks