Well, I tried to use what I already have working for DS3231
Manual is not very clear about I2C....
Well, I tried to use what I already have working for DS3231
Manual is not very clear about I2C....
Changed syntax, still getting zeroes, what I'm doing wrong?
Code:ldta var porta.6 lclk var porta.3 x var word y var byte z var byte cnt var byte 'control word adr var byte sda var portc.0 scl var portc.1 lcdout $fe, $01, " " adr=$23 x=0 cnt=%0100011 i2cwrite ldta, lclk, cnt, adr pause 200 cnt=%00010001 i2cwrite ldta, lclk, cnt, adr pause 200 maik: cnt=%0100011 i2cread ldta, lclk, cnt, adr, x pause 200 lcdout $fe, $1, dec x pause 200 goto maik
1 - use the appropriate I2C address for the device based on the hardware pin state
2) Slave Address
Slave Address is 2 types, it is determined by ADDR Terminal
ADDR = ‘H’ ( ADDR ≧ 0.7VCC ) → “1011100“
ADDR = 'L' ( ADDR ≦ 0.3VCC ) → “0100011“
2 - the device address for case 1 is $B8 and case 2 is $46 (use one of these values in cnt)
When you put the address as shown in your code, the leading bit is 0 and the address will be $5c or $23. This is definitely wrong.
3 - cnt remains the same for I2CWrite and I2CRead. the least significant bit is changed internally by the compiler depending on whether the command is a read or write
Thanks!
Tried both, none works, so I guess, I'm missing something else too...
You ought to be sending this way
make sure the adr and dat match with the register of the device and dat relevant to the register. It should work.Code:Assuming ADDR pin is low i2cwrite ldta, lclk, $46, adr, dat and read by i2cread ldat, lclk, $46, adr, dat
not in my viewYou ought to be sending this way
addr var byte
addr= $46
i2cwrite sda,sck,addr,[opecode]
i2cread sda,sck,addr,[dat.highbyte,dat.lowbyte]
Last edited by richard; - 17th May 2022 at 02:56. Reason: got rid of ridiculous alias names
Warning I'm not a teacher
Big thanks Richard! now it works!
here's the code:
Code:adr=$46 x=0 cnt=%0100011 i2cwrite ldta, lclk, adr, cnt pause 200 cnt=%00010001 i2cwrite ldta, lclk, adr, cnt pause 200 maik: cnt=%00010001 i2cwrite ldta, lclk, adr, cnt pause 200 cnt=%0100011 i2cread ldta, lclk, adr, [x.highbyte, x.lowbyte] pause 200 lcdout $fe, $1, dec x pause 200 goto maik
Bookmarks