Method for inter-integrated circuit (I2C) address allocation
A method for inter-intergrated circuit (I2C) address allocation includes the master device sending a notification signal to the plurality of slave devices via the bus, and after one of the plurality of slave devices receives the notification signal, the slave device generating a delay period, and detecting the serial data (SDA) signal of the, if not detecting the SDA signal having a high to low signal transition, at the end of the delay period the slave device updating the identification of the slave device, outputting low-pulse signal from the SDA pin and maintaining a low-pulse period, at the end of the low-pulse period, pulling the SDA signal to high, and detecting the SDA pins.
1 . A method for Inter-Integrated Circuit (I2C) bus address allocation in an I2C bus system, the system comprising a master device, a plurality of slave devices, and a bus, the master device and the plurality of slave devices being coupled to the bus, the method comprising:
outputting, by the master device, a notification signal to the plurality of slave devices via the bus;
when a slave device of the plurality of slave devices receives the notification signal, setting a Serial Data Line (SDA) pin of the slave device to a receive mode;
generating, by the slave device, a delay period;
detecting, by the slave device, a pin signal of the SDA pin during the delay period;
when no high-to-low transition is detected on the SDA pin during the delay period, updating a device identifier (ID) of the slave device and switching the SDA pin to an output mode at the end of the delay period;
outputting, by the SDA pin, a low-level pulse for a low-level period;
pulling the low-level pulse at the SDA pin to a high-level at the end of the low-level period; and
switching the SDA pin back to the receive mode to continue detecting a signal on the SDA pin.
2 . The method of claim 1 , further comprising:
when the SDA pin is at a low level, generating, by the slave device, another delay period.
3 . The method of claim 1 , further comprising:
when the SDA pin is at a high level, using an updated device ID, by the slave device, to communicate with the master device, after other slave devices of the plurality of slave devices have completed updating device IDs or after a preset period during which no voltage change on the SDA pin is detected.
4 . The method of claim 3 , wherein using the updated device ID, by the slave device, to communicate with the master device comprises:
sending out a packet by the master device;
when the slave device receives the packet, determining whether the device ID in the packet corresponds to the updated device ID;
if the device ID in the packet corresponds to the updated device ID, responding, by the slave device, according to content of the packet.
5 . The method of claim 1 , further comprising setting an initial value of the device ID to 0.
6 . The method of claim 1 further comprising:
recording, by the master device, a number of the plurality of slave devices according to a number of high-to-low voltage transitions on the bus after outputting the notification signal to the plurality of slave devices via the bus.
7 . The method of claim 1 , wherein the notification signal is a broadcast signal, a special command, a command string, or an I2C-defined general call.
8 . The method of claim 1 , wherein a length of the delay period is a random value, a product serial number, an internal table lookup value, or an initial register value.
9 . The method of claim 1 , wherein the device ID is assigned sequentially according to an incremental sequence, a decremental sequence, or a built-in address table.
10 . A method for Inter-Integrated Circuit (I2C) bus address allocation in an I2C bus system, the system comprising a master device, a plurality of slave devices, and a bus, the master device and the plurality of slave devices being coupled to the bus, the method comprising:
outputting a notification signal, by the master device, to the plurality of slave devices via the bus;
when a slave device of the plurality of slave devices receives the notification signal, setting a Serial Data Line (SDA) pin of the slave device to a receive mode;
generating, by the slave device, a delay period;
detecting, by the slave device, a pin signal of the SDA pin during the delay period;
updating a device identifier (ID) of the slave device according to the pin signal during the delay period;
when the pin signal of the SDA is at a high level at the end of the delay period, updating a device ID of the slave device and switching the SDA pin to an output mode;
outputting, by the SDA pin, a low-level pulse for a low-level period;
pulling the low-level pulse at the SDA pin to a high-level at the end of the low-level period; and
switching the SDA pin back to the receive mode to continue detecting a signal on the SDA pin.
11 . The method of claim 10 , wherein updating the device ID of the slave device according to the pin signal during the delay period comprises:
detecting high-to-low voltage pulse signal transitions on the SDA pin; and
updating the device ID based on a number of the high-to-low voltage pulse signal transitions;
wherein the device ID is different from a hardware ID of the slave device.
12 . The method of claim 10 , further comprising:
when the SDA pin is at a low level, generating, by the slave device, another delay period.
13 . The method of claim 10 , further comprising:
when the SDA pin is at a high level, using an updated device ID, by the slave device, to communicate with the master device, after other slave devices of the plurality of slave devices have completed updating device IDs or after a preset period during which no voltage change on the SDA pin is detected.
14 . The method of claim 13 , wherein using the updated device ID, by the slave device, to communicate with the master device comprises:
sending out a packet by the master device;
when the slave device receives the packet, determining whether the device ID in the packet corresponds to the updated device ID; and
if the device ID in the packet corresponds to the updated device ID, responding, by the slave device, according to content of the packet.
15 . The method of claim 10 , further comprising setting an initial value of the device ID to 0.
16 . The method of claim 10 , further comprising:
recording, by the master device, a number of the plurality of slave devices according to a number of high-to-low voltage transitions on the bus after outputting the notification signal to the plurality of slave devices via the bus.
17 . A method for Inter-Integrated Circuit (I2C) bus address allocation in an I2C bus system, the system comprising a master device, a plurality of slave devices, and a bus, the master device and the plurality of slave devices being coupled to the bus, the method comprising:
outputting, by the master device, a notification signal to the plurality of slave devices via the bus;
when a slave device of the plurality of slave devices receives the notification signal, setting a Serial Data Line (SDA) pin of the slave device to a receive mode;
generating a delay period by the slave device;
detecting, by the slave device, a pin signal of the SDA pin during the delay period;
updating a device identifier (ID) of the slave device according to the pin signal during the delay period;
when the pin signal is at a low level at the end of the delay period, generating another delay period by the slave device; and
detecting, by the slave device, the pin signal during the another delay period.
18 . The method of claim 17 , wherein updating the device ID of the slave device according to the pin signal during the delay period comprises:
detecting high-to-low voltage pulse signal transitions on the SDA pin; and
updating the device ID based on a number of the high-to-low voltage pulse signal transitions;
wherein the device ID is different from a hardware ID of the slave device.
19 . The method of claim 17 , wherein the notification signal is a broadcast signal, a special command, a command string, or an I2C-defined general call.
20 . The method of claim 17 , wherein a length of the delay period is a random value, a product serial number, an internal table lookup value, or an initial register value.