Andres Rodriguez
New Member
When I simulate the following code the "read i2c command" at the end yields erroneous data. Also the i2c tutorial does not say anything about hi2c commands although Manual#2 refers to the tutorial for more information. In the datasheet of the 24LC256 is not clear whether I should write word data or byte data. in this program all the variables are Word variables.
Code:
MEMDEVICE = %10100000 'First 24LC256 EEPROM, Second will be %10100010 and Third %10100100
MEMAD = 0 'Memory address
LCDOUT=0
PCOUT = 0
But = 0
Main:
If LCDOUT=1 then goto LCD_OUT 'Go to LCD OUT
If PCOUT=1 then goto Main1 'Go to PC OUT
RXIN = 0
High LED_POWER
Low LED_READ
Pause 100
pulsin 2,1,RXIN 'Receive command from TX
if RXIN<150 then goto Main
if MEMAD >= $7FFC then goto FIN
StartRead:
Toggle LED_READ,LED_POWER
'Measure temperature
i2cslave MEMDEVICE,i2cfast,i2cword
High CS 'idle
Low SCK
Low CS 'start transmission sequence
Temp = 0
For N = 1 to 16
High SCK
Temp = Temp * 2 + MISO
Low SCK
Next N
High CS 'terminate the transmission
Temp = Temp / 8 'use only the 13 most sig bits
Toggle LED_READ,LED_POWER
'Measure speed
readadc10 0,Speed
'Measure RPM
count 6, 5000, RPM ‘Count pulses in 5 seconds
Toggle LED_READ,LED_POWER
'Meassure G force
readadc10 1,Gy
readadc10 2,Gx
'Store in EEPROM
writei2c MEMAD,(Temp,Speed,RPM,Gy,Gx)
Pause 500
Temp=0
Speed=0
RPM=0
Gy=0
Gx=0
readi2c MEMAD,(Temp,Speed,RPM,Gy,Gx)
MEMAD=MEMAD+10
GOTO Main