Did you put the two pull-up 4.7k resistors in the SDA and SCL lines?
Robert
Did you put the two pull-up 4.7k resistors in the SDA and SCL lines?
Robert
"No one is completely worthless. They can always serve as a bad example."
Anonymous
Also, you don't need to worry about anything that you highlighted in red. The I2CREAD and I2CWRITE commands take care of that for you.
Robert
"No one is completely worthless. They can always serve as a bad example."
Anonymous
My Code is this:
PortC.2 keeps toggling along with normal LED.Include "modedefs.bas"
DEFINE OSC 4
#CONFIG
ifdef PM_USED
device pic16F688, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
else
__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_ON & _CPD_ON & _BOD_ON & _IESO_ON & _FCMEN_ON
endif
#ENDCONFIG
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 3
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 1
DEFINE I2C_SLOW 1
'DEFINE I2C_HOLD 1
'-----------------------------------------------------
PORTA=0
PORTC=0
TRISA = %000100
TRISC = %110000
CMCON0 = 7
ANSEL = 0
OPTION_REG = 128
INTCON=128
'-----------------------------------------------------
Value Var word
'------------------------------------------------------------
SCL Var PortC.5
SDA Var PortC.4
Change Var PortA.2
LED Var PortC.0
'---------------------------------------------------------
Pause 500
DEBUG "Start......",13,10
value=0
Main:
High Led : Pause 1000: Low Led : PAUSE 1000
I2CREAD SDA,SCL,$1B,0,[VALUE],Fail
PAUSE 25
DEBUG HEX Value,13,10
PAUSE 250
DEBUG "Done....",13,10
Goto Main
Fail:
toggle portc.2
goto main
I have also attached the device datasheet. I really appreciate the help in this.
From PBP manual about I2CREAD:
"Constants should not be used for address..."
Don't know if this can help.
Robert
Last edited by Demon; - 27th July 2013 at 13:46.
I added two bytes - Addr & Loc
Addr=$1B
Loc=0
Sent - I2CREAD SDA,SCL,Addr,Loc,[Value],Fail
No Luck
'-----------
What is also confusing me is the control byte in the manual, the device datasheet does not mention any control byte.
I have an address $1B which I am sending as control and location in the device is being sent as Address according to the manual.
Last edited by FromTheCockpit; - 27th July 2013 at 16:18. Reason: More info
I thought I saw 9 bits used from control in the datasheet you linked.
Maybe you're supposed to use a word and ignore the other 7 bits? Or that could be handled by PBP for I2C?
Do you get only a byte back, word, multiple bytes?
Your circuit does make address 0 right?
(just throwing ideas at you)
Robert
Steps Taken:
1) Configuration changed: _INTRC_OSC_NOCLKOUT
2) Made 16f688 run at 8MHz : OSCCON=%01110001
3) Commented DEFINE I2CSLOW 1
4) Value changed to BYte (then to word again)
I get a byte back from the device (from what I have understood). Yes there is an address 0 in the device. I should get back chip ID i.e-'2E' as per the datasheet.
Still no Luck.
I couldn't find detailed info on the Write/Read bit of the device address. But I will guess it is bit 7.
You need to Write to the device first using the address with the "Write" bit set.
$1B or %00011011 becomes $9B or $10011011
Without confirming the proper syntax of the commands, here's something off the top of my noodle:
This will cover steps 1~4 of Section 4.3.2 of the datasheet
Code:I2CWRITE SDA,SCL,[Addr,Loc,] ' Addr plus Write bit = $9B
This will cover steps 5~7 of Section 4.3.2 of the datasheet
Putting it together should get you moving in the right direction.Code:I2CREAD SDA,SCL,[Addr,Loc] ' Addr plus Read bit = $1B
Here's a note to myself that might come in handy too:Code:I2CWRITE SDA,SCL,[Addr,Loc,] ' Addr plus Write bit = $9B I2CREAD SDA,SCL,[Addr,Loc] ' Addr plus Read bit = $1B
Last edited by LinkMTech; - 27th July 2013 at 16:53. Reason: Added I2C screen shot notes
Louie
The device you are using is a fast mode device (400 khz) so you have to remove the "DEFINE I2C_SLOW 1" and very likely you have to increase your clock speed (4 MHz could be too slow). Also change the variable into byte (you are using word).
Good luck
Al.
All progress began with an idea
Bookmarks