Hello igorkhod,
later on i did not use adxl312 instead i used adxl345 because adxl312 was not available in small quantity.
adxl312 is similar to adxl345, if i can remember correctly adxl312 have more resolution than adxl345.
if you are working with adxl312 first try to read device ID. below code is for adxl345
i2c_out VAR BYTE 'data to sent over I2C bus
i2c_in VAR BYTE[2] 'data received over I2C bus
i2c_ack VAR BIT 'acknowledgement bit
loop:
GOSUB I2C_START 'Start Condition
i2c_out = $A6
GOSUB I2C_TX 'Send data in “i2c_out”
i2c_out = $00
gosub I2C_TX
GOSUB I2C_STOP 'Stop Condition
GOSUB I2C_START 'Start Condition
i2c_out = $A7
GOSUB I2C_TX 'Send data in “i2c_out”
GOSUB I2C_RX
GOSUB I2C_STOP 'Stop Condition
goto loop
I2C_START: 'I2C start (start communication on I2C bus)
HIGH SDA
HIGH SCL
LOW SDA
LOW SCL
RETURN
I2C_STOP: 'I2C stop (terminate communication on I2C bus)
LOW SDA
HIGH SCL
HIGH SDA
PAUSE 1
RETURN
I2C_RX: 'I2C receive -> receive data from slave
SHIFTIN SDA,SCL,0,[i2c_in[0]] 'Shift in first byte MSBpre
SHIFTOUT SDA,SCL,1,[%0\1] 'Send acknowledge (ACK) = 0
SHIFTIN SDA,SCL,0,[i2c_in[1]] 'Shift in second byte MSBpre
SHIFTOUT SDA,SCL,1,[%1\1] 'Send not acknowledge (NACK) = 1
RETURN
I2C_TX: 'I2C transmit -> send data to the slave
SHIFTOUT SDA,SCL,1,[i2c_out] 'Shift out “i2c_out” MSBfirst
SHIFTIN SDA,SCL,0,[i2c_ack\1] 'Receive ACK bit
'if i2c_ack = 1 then
'SEROUT tx,T9600,["ACK NOT RECEIVED FOR"]
'SEROUT tx,T9600,[#i2c_out]
'SEROUT tx,T9600,[":"]
'SEROUT tx,T9600,[#i2c_ack,10]
'endif
RETURN
Bookmarks