Further investigation has revealed why your checksum still worked.... (sorry for the rather brief earlier reply - it was from my mobile phone!). If we use the following code:
Code:
I2CAddr Var byte
Xray var byte
Alpha var byte
I2CAddr2 var byte
I2CDevice var byte
I2cdevice =160
I2CAddr2 = 0
for i2caddr = 0 to 2048 step 16
i2cwrite d1,d2,i2cdevice,i2caddr,[$55]
hserout [hex I2CAddr, " "]
pause 10
next
This reveals that with i2caddr as a byte, the for/next loop assigns the following values to I2CAddr:
0 10 20 30 40 50 60 70 80 90 A0 B0 C0 D0 E0 F0
then stops (whereas as a word continues up to 800 as expected).
So you are actually only writing to a memory address up to F0, but then reading back gives you the correct checksum. However where are you actually writing to memory? - Well the memory assignment by PBP is sequential in alphabetic order, words first then bytes, and the next byte after I2CAddr is in fact I2CDevice in your code, or in my modification, I2CAddr2, as is seen here:
Code:
_Alpha EQU RAM_START + 018h
_I2CAddr EQU RAM_START + 019h
_I2CAddr2 EQU RAM_START + 01Ah
_I2CDevice EQU RAM_START + 01Bh
_Xray EQU RAM_START + 01Ch
Now the PBP manual states "The Address size sent (byte or word) is determined by the size of the variable that is used. If a byte-sized variable is used for the Address, an 8-bit address is sent. If a word-sized variable is used, a 16-bit address is sent. Be sure to use the proper sized variable for the device you wish to communicate with."
I suspect this is in fact not correct and looking at the assembler code that PBP generates, in fact I2CWRITE seems to send a word, using I2CAddr, I2CAddr2 as the (word) address in my example, or the case of your code, actually I2CAddr, I2CDevice (=$A0) which is I suspect somewhere other than you intended in memory!
Peter
Bookmarks