I set up I2C capture and it looks suspicious.
The 1st entry at "data" is actually and address of the chip
and 3rd entry - the address I'm sending to it for reading
but I'm getting no response?
![]()
I set up I2C capture and it looks suspicious.
The 1st entry at "data" is actually and address of the chip
and 3rd entry - the address I'm sending to it for reading
but I'm getting no response?
![]()
yet still another pointless snippet , with nothing defined
I2CREAD DPIN,CPIN,$A0,B0,X
you persist in using incorrect syntax , it should be
I2CREAD DPIN,CPIN,$A0,B0,[X ]
proper code, not snippet with undefined rubbish, its not hard
what a write looks likeCode:#CONFIG __config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF __config _CONFIG2, _PLLEN_ON & _LVP_OFF #ENDCONFIG ;pic16f1825 DEFINE OSC 32 OSCCON=$70 ANSELA=0 ANSELC=0 trisa.0=0 DEFINE I2C_SLOW 1 ANSELA = 0 a Var Byte addr Var word ar Var Byte SCL var Porta.2 SDA var Porta.1 lata.0=1 DEFINE DEBUG_REG PORTA DEFINE DEBUG_BIT 0 ; if not used for pwr DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 pause 2000 Debug 13,10,"Start",13 ,10 a=20 addr=$200 I2cwrite Sda,SCL,$a0 ,addr,[a] pause 10 addr=$200 I2CREAD Sda,SCL,$a0 ,addr,[ar ] debug 13,10,sdec ar end
what a read looks like
![]()
Last edited by richard; - 9th October 2021 at 09:18.
Warning I'm not a teacher
Well, if there's syntax error, compiler should warn about it, right?
I tried to add brackets and now it starts working, but in the weird way.
I2CWRITE DPIN,CPIN,$A0,B0,[127]
Writes 127 into eeprom
but if I substitute variable there, no matter, byte or word
after reading, I'm getting zeroes.
no the compiler produces code to I2CREAD DPIN,CPIN from device $A0 @eeprom address B0,X then read nothing as asked for
there is no error
produce a compliable example that demonstrates the problemI tried to add brackets and now it starts working, but in the weird way.
I2CWRITE DPIN,CPIN,$A0,B0,[127]
Writes 127 into eeprom
but if I substitute variable there, no matter, byte or word
after reading, I'm getting zeroes.
Warning I'm not a teacher
Code:DPIN Var PORTA.2 ' I2C data pin CPIN Var PORTA.1 ' I2C clock pin B0 Var word B1 Var byte B2 Var byte X var byte x=0 For B0 = 0 To 15 b1=b2 I2CWRITE DPIN,CPIN,$A0,B0,[99] Pause 10 ' pause 100 Next B0 mainloop: For B0 = 0 To 15 I2CREAD DPIN,CPIN,$A0,B0,[X] lcdout $fe, $1, dec b0, " ", dec X pause 1000 Next B0 Goto mainloop End
so we guess whats wrong thenCode:DPIN Var PORTA.2 ' I2C data pin CPIN Var PORTA.1 ' I2C clock pinB0 Var wordB1 Var byteB2 Var byteX var bytex=0 For B0 = 0 To 15 b1=b2 I2CWRITE DPIN,CPIN,$A0,B0,[99] Pause 10 'pause 100 Next B0mainloop: For B0 = 0 To 15 I2CREAD DPIN,CPIN,$A0,B0,[X] lcdout $fe, $1, dec b0, " ", dec X pause 1000 Next B0 Goto mainloopEnd
DPIN,CPIN are analog
the chip[undefined] has no porta
the vcc is too low
the clock is too fast
the lcd is not setup properly
the config settings are incorrect
the interrupt in the unseen part of the code is ruining the timing
what's the point
Last edited by richard; - 10th October 2021 at 08:38.
Warning I'm not a teacher
this
produces as expected thisCode:'* pic16f1825 : eprom addr =$a0 #CONFIG __config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF __config _CONFIG2, _PLLEN_ON & _LVP_OFF #ENDCONFIG DEFINE OSC 32 OSCCON=$70 ANSELA=0 ANSELC=0 trisa.0=0 DEFINE I2C_SLOW 1 ANSELA = 0 B0 Var word X var byte SCL var Porta.2 SDA var Porta.1 lata.0=1 DEFINE DEBUG_REG PORTA DEFINE DEBUG_BIT 0 ; if not used for pwr DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 pause 2000 Debug 13,10,"Start",13 ,10 clear For B0 = 0 To 15 I2CWRITE sda,scl,$A0,B0,[99] Pause 10 ' Next B0 pause 100 mainloop: For B0 = 0 To 15 I2CREAD sda,scl,$A0,B0,[X] debug 13,10, dec b0, " ", dec X Next B0 pause 1000 Goto mainloop end
Code:Start 0 99 1 99 2 99 3 99 4 99 5 99 6 99 7 99 8 99 9 99 10 99 11 99 12 99 13 99 14 99 15 99
Warning I'm not a teacher
Bookmarks