I will tray out the new code on Monday. Can you tell me for what is the [ ] ?
The Pull Up resistors are on the board.
Thanks
I will tray out the new code on Monday. Can you tell me for what is the [ ] ?
The Pull Up resistors are on the board.
Thanks
Last edited by Omalik; - 1st June 2008 at 18:17.
Here is an example of how I use I2C with an EEPROM and the I/O Expander, I hope it helps.
DEFINE I2C_HOLD 1
Address VAR WORD
SCL VAR PORTC.3 ' I2C Clock pin
SDA VAR PORTC.4 ' I2C Data pin
Address = 0
'------------------------------------------------------------------------------------------------
' Read Password from EEPROM
'------------------------------------------------------------------------------------------------
ReadPassword:
Address = 0
I2CREAD SDA,SCL,$A0,Address,[Password[1],Password[2],Password[3],Password[4]]
Return
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------
' Save Password to EEPROM
'------------------------------------------------------------------------------------------------
SavePassword:
Address = 0
I2CWRITE SDA,SCL,$A0,Address,[Password[1],Password[2],Password[3],Password[4]]
Return
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------
' Subroutine to handle I2C errors
'------------------------------------------------------------------------------------------------
I2CError:
LCDOut $fe,1
LCDOut $fe,2, "I2C Bus Timed Out" ' I2C command timed out
Pause 1000
GoTo loop
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------
' Setup I2C I/O Expander
'------------------------------------------------------------------------------------------------
SetupIOExpander:
'*** Setup I/O Expander PortA as Output, PortB as Input ***
I2CWrite SDA,SCL,$40,[6,0,31], I2CError
Pause 150
'*** Set the Interrupt Capture Rate to Fast ***
'I2CWrite SDA,SCL,$40,[11,1], I2CError
'Pause 150
'*** Set I/O Expander PortA Outputs to LOW ***
I2CWrite SDA,SCL,$40,[0,0], I2CError
Pause 150
RESUME
'------------------------------------------------------------------------------------------------
I tray out
I2CRead I2C_data,I2C_clock,$F1,0,[druck,druck2]
but it does not work at all. I find a lot of examples for Eeprom but not one for the sensor I use.
does some have any idea ?
Thanks
From what I can see in the data sheet you should be using this:
I2CRead I2C_data,I2C_clock,$F1,[druck,druck2]
I don't know what the 0 you had there was for but the R/W bit is set by the I2CRead/I2CWrite command, you don't need to set it.
also check what you have druck and druck2 declared as, byte or word.
i did a picture on the KO.
blue is clock and red are data.
and i can not read the sensor.
Last edited by Omalik; - 8th June 2008 at 18:46.
Bookmarks