I am trying to change the address on my SRF08s. I have confirmed they
work ie I did a ping on each of them with the default address. In order
to change the address I need to send A0, AA, A5 and then the desired
address. This I put into cmd before calling the routines.
I called the following routine. I do not think I have the TWI calls
right. It returned invalid address.
int8_t srf08_ChangeAddress(uint8_t device, uint8_t Newdevice)
{
uint8_t cmd;
uint8_t addr;
/* start condition */
if (i2c_start(0x08, 1))
return -1;
/* address slave device, write */
if (i2c_sla_rw(device, 0, TW_MT_SLA_ACK, 1))
return -2;
// write to the command register
addr = 0;
/* write address */
if (i2c_data_tx(addr, TW_MT_DATA_ACK, 1))
return -3;
/* repeated start condition */
if (i2c_start(0x10, 1))
return -4;
cmd = 0xA0;
/* write command */
if (i2c_data_tx(cmd, TW_MT_DATA_ACK, 1))
return -5;
cmd = 0xAA;
/* write command */
if (i2c_data_tx(cmd, TW_MT_DATA_ACK, 1))
return -6;
cmd = 0xA5;
/* write command */
if (i2c_data_tx(cmd, TW_MT_DATA_ACK, 1))
return -7;
/* write command */
if (i2c_data_tx(Newdevice, TW_MT_DATA_ACK, 1))
return -8;
if (i2c_stop())
return -9;
return 0;
}
Do I need to need to write the device and address for each byte of data?Message
TWI (I2c) Question
2004-12-25 by wbounce
Attachments
- No local attachments were found for this message.