Sorry for all those contiuous posts! just wanted to let you know that the problem is fixed now.
Apparently when you want to write to this SPI memory a 16bit value (word) you don't have to write the first 8bits then increase the address by one and then write the following 8 bits. You just set the initial address and then enter the two 8bit values you want to store and the address is increased automatically. In order to read from the eeprom though you do need to increase the address (i think). I give the following working code for reference:
================================================== =======
' PIC setting & Programming mode
' -------------------------------
'
' HS(10Mhz) oscillator
' Enable watch dog timer
' Enable power up timer
' Enable brown out detect
' Disable low voltage programming
'Usart Settings
' --------------
'
DEFINE HSER_RCSTA 90h 'Enable Serial PORT
'8 bit reception
'Disable Single receive
'Enable continuous receive
'All bytes received, diable address detection
'No framming Error
'No overrun error
DEFINE HSER_TXSTA 20h '8 bit transmission
'Enable transmit
'Asyncronous mode
'Low baud rate (BRGH=0)
'TSR full
DEFINE HSER_SPBRG 64 'set USART to 2400 baud (when BRGH=0)
DEFINE HSER_CLROERR 1 'Enable automatic overrun error
'Oscillation Settings
'---------------------
DEFINE OSC 10 'Oscillation Speed 10MHz
'ADC settings
'-------------
DEFINE ADC_BITS 10 '10 bits conversion
DEFINE ADC_CLOCK 3 'Clock cycle (3=rc)
DEFINE ADC_SAMPLEUS 50 'Sampling time in ìs
INCLUDE "modedefs.bas"
CS var PORTA.5 ' Chip select pin
SCK var PORTC.3 ' Clock pin
SI var PORTC.4 ' Data in pin
SO var PORTC.5 ' Data out pin
addr var word ' Address
adc var word ' Result from ADC
adc1 var word ' read from memory result
TRISA.5 = 0 ' Set CS to output
trisa = %11011111
adcon1 = %10001110
addr = 0
MAIN:
adcin 0,adc
hserout [#adc,13]
gosub eewrite
pause 500 ' Delay after each write
gosub eeread
hserout [#adc1,13] 'Display the result from eeprom read
pause 1000
addr = addr + 1
goto main
' Subroutine to read data from addr in serial EEPROM
eeread:
CS = 0 ' Enable serial EEPROM
Shiftout SI, SCK, MSBFIRST, [$03, addr.byte1, addr.byte0]
Shiftin SO, SCK, MSBPRE, [adc1.Byte1] ' Read data
cs = 1
pause 500
addr = addr + 1
cs = 0
Shiftout SI, SCK, MSBFIRST, [$03, addr.byte1, addr.byte0]
Shiftin SO, SCK, MSBPRE, [adc1.byte0] ' Read data
CS = 1 ' Disable
Return
' Subroutine to write data at addr in serial EEPROM
eewrite: CS = 0 ' Enable serial EEPROM
Shiftout SI, SCK, MSBFIRST, [$06] ' Send write enable command
CS = 1
CS = 0 ' Enable
Shiftout SI, SCK, MSBFIRST, [$02, addr.byte1, addr.byte0, adc.byte1, adc.byte0]
cs = 1
pause 500
Return
================================================== ========
The pause values can be much smaller I guess!
Bookmarks