/* * change_add.c v2.0 * * This is driver/utility program to use with mindsensors.com sensor to * change the address. * * written by Dr. Nitin Patil * 2006(c) mindsensors.com */ /* * NXT I2C register storage * * 0x41 is command register * writing 0xA0 0xAA 0x A5 and will change the address of * the device to new address * New address is effective immediately. */ ////////////////////////////////////////////////////////////////////////////// // // change the adress of the I2C sensor oldAddresswith the NewAddress // ///////////////////////////////////////////////////////////////////////////// void Change_add(byte oldAddress,byte newAddress) { byte i2cMsg[8]; const byte kMsgSize = 0; const byte kDeviceAddress = 1; const byte kCommandAddress = 2; const byte kCommand = 3; nI2CBytesReady[S1] = 0; SensorType[S1] = sensorI2CCustomStd9V; // Build the I2C message i2cMsg[kMsgSize] = 3; i2cMsg[kDeviceAddress] = oldAddress ; i2cMsg[kCommandAddress] =0x41; i2cMsg[kCommand]=0xA0; while (nI2CStatus[S1] == STAT_COMM_PENDING); // Wait till I2C bus is ready sendI2CMsg(S1, i2cMsg[0], 0); // Send the message wait10Msec(10); i2cMsg[kCommand]=0xAA; while (nI2CStatus[S1] == STAT_COMM_PENDING); // Wait till I2C bus is ready sendI2CMsg(S1, i2cMsg[0], 0); // Send the message wait10Msec(10); i2cMsg[kCommand]=0xA5; while (nI2CStatus[S1] == STAT_COMM_PENDING); // Wait till I2C bus is ready sendI2CMsg(S1, i2cMsg[0], 0); // Send the message wait10Msec(10); i2cMsg[kCommand]=newAddress; while (nI2CStatus[S1] == STAT_COMM_PENDING); // Wait till I2C bus is ready sendI2CMsg(S1, i2cMsg[0], 0); // Send the message wait10Msec(10); } ////////////////////////////////////////////////////////////////////////////// // // demo main function to show change adress function // ///////////////////////////////////////////////////////////////////////////// task main() { nxtDisplayTextLine(1, "mindsensors.com"); nxtDisplayTextLine(2, "address change"); Change_add(0x02,0xa8); StopAllTasks(); } /* This is driver/utility program to scan the devices on the NXT portsdefault port is port 1. V1.1 written by Dr. Nitin Patil 2006(c) mindsensors.com for more info visit www.mindsensors.com */