Open shivakumar-tekumatla opened 2 years ago
I have contacted AMS about this , and it seems to be procedure to change the device ID is different from what is given in the documentation. Update procedure looks like below. This is taken from their email to me, and also tested.
Thanks for the detailed information. I'll take a look at this and get it fixed/tested - probably in the next couple weeks. -Kirk
@shivakumar-tekumatla, I took a crack at fixing the address change using your suggested code. I'm not able to get it to work. Perhaps you can post the actual code you used? Thanks.
@hartmms , I was able to change using below program. I wrote the program in python .
def I2C_Chg_Fun(self,new_addr):
new_addr = (((new_addr&0x7F) <<1) & 0xFE) # Shifting by one bit
self.bus.write_byte_data(self.I2C_ADDR,self.GPIO_0_REG,0x5)
self.bus.write_byte_data(self.I2C_ADDR,self.GPIO_1_REG,0x5)
self.bus.write_byte_data(self.I2C_ADDR, self.CMD_STAT_REG, self.LOAD_CONFIG_CMN ) #Step-1
self.STAT_OK = 0x20 #assigning a random value first
while self.STAT_OK>=0x10: # Step-2 : Read until a value less than 0x10 is transmitted
self.STAT_OK = self.bus.read_byte_data(self.I2C_ADDR, self.CMD_STAT_REG)
time.sleep(0.1)
self.bus.write_byte_data(self.I2C_ADDR,self.I2C_SLAVE_ADDR_REG,new_addr)
time.sleep(0.5)
self.bus.write_byte_data(self.I2C_ADDR,self.I2C_ADDR_CHG_REG,0xF)
time.sleep(0.5)
self.bus.write_byte_data(self.I2C_ADDR,self.CMD_STAT_REG,0x15)
time.sleep(0.5)
self.bus.write_byte_data(self.I2C_ADDR,self.CMD_STAT_REG,0x21)
time.sleep(0.5)
Please note that I wrote this program after writing image to the sensor and confirming the application code to be 0x03.
I know it's been a while, but I tried getting a .cpp version of above working, and it isn't working for me. The code below seems to have no effect. Has anyone got this working from within the library?
Serial.printf("setting I2C address to 0x%02x\n", address);
// shift address by one bit
address = ((address&0x75)<<1)&0xfe;
// Change 0x31 GPIO_0 & 0x32 GPIO_1 registers to 0x5 (Output high)
_i2cBus->writeRegisterByte(_i2cAddress, TMF8X2X_COM_GPIO_0, 0x5);
delay(500);
_i2cBus->writeRegisterByte(_i2cAddress, TMF8X2X_COM_GPIO_1, 0x5);
delay(500);
_i2cBus->writeRegisterByte(_i2cAddress, TMF8X2X_COM_CMD_STAT, TMF8X2X_COM_CMD_STAT__cmd_stat__CMD_LOAD_CONFIG_PAGE_COMMON);
delay(500);
// wait for status to be less than 0x10
uint8_t status = 0x20;
while (status >= 0x10) // read until a value less than 0x10 is transmitted
{
_i2cBus->readRegisterRegion(_i2cAddress, TMF8X2X_COM_CMD_STAT, &status, 1);
delay(100);
}
_i2cBus->writeRegisterByte(_i2cAddress, TMF8X2X_COM_I2C_SLAVE_ADDRESS, address);
delay(500);
_i2cBus->writeRegisterByte(_i2cAddress, TMF8X2X_COM_I2C_ADDR_CHANGE, 0xf);
delay(500);
_i2cBus->writeRegisterByte(_i2cAddress, TMF8X2X_COM_CMD_STAT, TMF8X2X_COM_CMD_STAT__cmd_stat__CMD_WRITE_CONFIG_PAGE);
delay(500);
_i2cBus->writeRegisterByte(_i2cAddress, TMF8X2X_COM_CMD_STAT, TMF8X2X_COM_CMD_STAT__cmd_stat__CMD_I2C_SLAVE_ADDRESS);
Serial.printf("I2C address now reads as 0x%02x\n", getI2CAddress());
@berickson , can you try with a different delay between the commands? Maybe 1 second ? I do not know if this is the case , but I remember changing the delays when switching from python to cpp.
@shivakumar-tekumatla Thanks for the reply. I tried changing all delays to 1 second and didn't get any change in behavior.
@berickson , another reason could be the factory firmware might have changed since then. Are you using the latest one ? if that is the case can you try following the actual method from the documentation. I remember talking to them to change the process and the documentation. They might have done that
I encountered the same issue as described in this GitHub issue while working with C code. However, I was able to resolve it and would like to share my solution. It seems that the firmware defined in tof_bin_image.c
is outdated and likely contains bugs related to TMF882X. I downloaded the latest hex file from the TMF882X website and resolved the issue by specifying hex mode when calling fwdl
. I hope this information is helpful.
@b1uep0nd thanks for your comment. Please post your solution.
@b1uep0nd I'll try with the udpated hex. Before I start, I'm curious. After you set the I2C address, does it survive reboots and firmware uploads or does the address need to be set every time the devices start up?
I modified the loadFirmware
function like this. The firmwareBinImage
is the latest HEX data downloaded.
// Load the fireware.
if (tmf882x_fwdl(&_TOF, FWDL_TYPE_HEX, firmwareBinImage, length))
@berickson You will need to set the address every time the device starts up.
I tried setting a new I2C ID using setI2CAddress function. The function returns True , but the communication fails. I tried the following program . I also attached the I2C communication data capturing using Saleae logic analyzer.