try $a6 for the i2cread address as well as the write address , pbp will set bit.0 of the address as required
try $a6 for the i2cread address as well as the write address , pbp will set bit.0 of the address as required
It looks good to me. You need to check your connections and scope it and see if you're actually talking to it.
See post# 8 where the I2CREAD was used same as yours, just different address.
Louie
There was a recent thread that explained that you have to shift the seven bit address left, and let PBP insert bit 0 for the I2Cread or I2C write command. Using both a barometer chip and a humidity chip I made the address a constant, then made a variable that shifted the constant left one bit, and used that variable as the address.
HTU21D_i2c_address con $40
HTU21D_i2c_address1 var byte
HTU21D_i2c_address1 = HTU21D_i2c_address <<1
i2cwrite SDA, SCL, HTU21D_i2c_address1, [trig_temp]
pause 10
i2cread SDA, SCL, HTU21D_i2c_address1, [temp]
pause 10
i2cwrite SDA, SCL, HTU21D_i2c_address1, [trig_RH]
pause 10
i2cread SDA, SCL, HTU21D_i2c_address1, [RH]
try something like this using the $1D address as the constant, shift it once, and let PBP add bit 0
Thanks for everyone's input.
The main issue was Louie's point, the ADXL345 is a QFN part and I had a bad solder joint.
From the ADXL345 data sheet, the read/write addresses are given as $A6 and $A7 which do take into account the read/write bit and it is this value used in the I2C PBP code. I added a label to the I2C commands which allows a jump if there is an I2C communication error talking to the device. I added this label for all commands sent whether read or write, this error occurred for every command which directed me to investigating the hardware. Adding the label was a very valuable diagnostic tool.
Below is my working code for the ADXL345, much more work is still needed to get the device configured for my application and get the raw counts into meaningful values. Overall the PBP I2C commands work great and are simple to use.
Code:X0 var byte X1 var byte Y0 var byte Y1 var byte Z0 var byte Z1 var byte ID var byte Mode var byte high ADXL345_CS ' Set high to put unit into I2C mode pause 1 ' Added to insure no R/W issue low ADXL345_SDO ' Set low to put unit addresses to $A6, $A7 pause 1 ' Added to insure no R/W issue serout2 RS232_TX, 6, [13,13,10,"Start of Test Program. "] 'Initialize ADXL345 I2Cread ADXL345_SDA,ADXL345_SCL, $A7,$00, [ID], I2C_error 'read Device ID serout2 RS232_TX, 6, ["Device ID: $", hex2 ID,13,10] ' Value should be $E5 I2CWRITE ADXL345_SDA,ADXL345_SCL, $A6, $31, [$0B], I2C_error '+/-16g, 13-bit mode pauseus 5 I2CWRITE ADXL345_SDA,ADXL345_SCL, $A6, $2D, [$08], I2C_error 'Start Measurement or put into Run Mode pauseus 5 I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $2D, [Mode],I2C_error ' Confirm mode setting serout2 RS232_TX, 6, ["Mode: ",hex Mode,13,10] ' value should be 8 pauseus 5 Main_I2C: ' Main Loop I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $32, [X0,X1,Y0,Y1,Z0,Z1], I2C_error serout2 RS232_TX, 6, ["X,Y,Z, ", Sdec 256*X1+X0,", ",Sdec 256*Y1+Y0,", ",Sdec 256*Z1+Z0,13,10] pause 100 Goto Main_I2C I2C_Error: serout2 RS232_TX, 6, ["I2C Comm Error",13,10] stop
Bookmarks