i2c problem writing the values of 5 Word variables(yes, I did a search)

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
 

BCJKiwi

Senior Member
Never had any joy simulating i2c devices.

The values can be entered manually in the simulator to test your code logic, after that it seems the program must be run in the chip to test further.
 

Shack

Member
Not sure but I use this command in the beginning of the code and mine works fine on a 28x part. I am using a 16 Mhz crystal tho.

I am using the 24LC256 and 512.

'Initialize i2C.
Hi2csetup I2cmaster, %10100010, i2cfast_16, i2cWord
 

BCJKiwi

Senior Member
Please note earlier posts regarding speed settings:-

ISSUE:- All forms of the current i2cslow_16 parameter with or without the _16 part and fast or slow all produce the same low i2c clock speed at any PICAXE processor clock speed.

AFFECTED:- hi2csetup mode parameter for 28X1, 28X2 and 40X1, 40X2 using compiler in the Programming Editor versions ?? to and including 5.1.5, 5.1.6, 5.1.7.

WORKAROUND:- use the values in the following table.

Note:- Unlike serial where a new speed can be used for each transmission, for i2c only one speed is supported on the bus within a program (unless you turn the devices on and off?). Where devices supporting different i2c clock speeds are used on the same bus, only the lowest speed should be used.


Code:
    Functional Mode Parameters
    hi2csetup       PICAXE      i2c
    MODE            Clock       Clock
    ----------------------------------
    i2cany          any         32KHz
    137             4MHz        100kHz
    147             8MHz        100kHz
    167             16MHz       100kHz
    1               4MHz        400kHz
    4               8MHz        400kHz
    9               16MHz       400kHz
    For example:- 
        hi2csetup i2cmaster,RTC_0,167,i2cbyte
        where RTC_0 is the device address
    Speeds verified with an oscilloscope
    for a 28X1 at 16MHz clock speed.
 

Technical

Technical Support
Staff member
The simulation only supports 2 types of eeprom 24LC16B and 24LC128. You can select these via the View>Options>Simulation menu.

256, 512 both use word mode for the address location (although data actually written or read is still a byte).

so
Hi2csetup I2cmaster, %10100010, i2cfast_16, i2cWord
is correct - if the part is at address %010 (A1 high, A0 and A2 low)
 
Top