Strategy for MCU to carry out automatic addressing on proximity sensor

By building a preset address pool in Flash, the MCU automatically finds the valid physical address of the proximity sensor, which solves the problem of poor communication flexibility between the MCU and the proximity sensor, and realizes multi-model adaptation and cost savings.

CN120849329APending Publication Date: 2025-10-28HUANGSHAN AUTOMOBILE ELECTRIC EQUIP CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510898459.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-01
Publication Date
2025-10-28

AI Technical Summary

Technical Problem

The existing I2C communication method between MCUs and proximity sensors has poor flexibility, which means that different sensor models require different MCU software adaptations, and software updates are required when replacing sensors, increasing production costs.

Method used

A preset address pool is built in Flash, and valid physical addresses are found by scanning the I2C bus and the addresses are automatically adapted, supporting automatic addressing of multiple sensor models.

Benefits of technology

It enables flexible adaptation between the MCU and proximity sensor models, reduces production costs and software update time, and improves communication flexibility and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120849329A_ABST
    Figure CN120849329A_ABST
Patent Text Reader

Abstract

The invention provides a strategy for an MCU to carry out automatic addressing on a proximity sensor. Constructing a preset address pool in the Flash; judging whether an effective physical address exists in a memory or not; if yes, taking the current effective physical address to carry out communication work; if not, the first slave equipment physical address is taken out from the top of the preset address pool, a read instruction is generated, and whether a slave equipment ACK response signal exists on the I2C bus or not is scanned; and if the slave equipment ACK response signal is received, the current slave equipment physical address is an effective address, the effective physical address is written into the memory, and the effective physical address is taken for communication. According to the invention, the problems of poor flexibility of the pairing mode of the MCU and the proximity sensor and high cost of replacing the proximity sensor in the prior art are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of I2C communication technology, and in particular to a strategy for MCU to automatically address proximity sensors. Background Technology

[0002] Currently, I2C communication between the MCU and proximity sensors uses a fixed address method. This means the MCU writes the proximity sensor address into its software and communicates using that fixed address during operation; this method cannot be changed. This approach has the following drawbacks: 1. Poor flexibility: The MCU software must correspond one-to-one with the proximity sensor model; different proximity sensor models require different software from the MCU for adaptation. 2. When different proximity sensor models are used in production, the MCU software cannot adapt to the new proximity sensor communication address, leading to functional failure. 3. When costs change and a lower-cost proximity sensor model is desired, time is required to update the software and track the transition between old and new states, incurring additional production costs. Therefore, a new automatic addressing strategy is needed to solve these problems. Summary of the Invention

[0003] The purpose of this invention is to provide a strategy for automatic addressing of proximity sensors by an MCU, which solves the problems of poor flexibility in the existing pairing method between MCU and proximity sensors and high cost of replacing proximity sensors.

[0004] The technical solution adopted by the present invention to solve its technical problem is:

[0005] A preset address pool is constructed within the Flash memory, the preset address pool including several slave device physical addresses that need to be traversed;

[0006] Start addressing to determine if a valid physical address exists in the memory;

[0007] If the determination is yes, then the current valid physical address is used to communicate with the I2C device;

[0008] If the determination is negative, the first slave device physical address is retrieved from the top of the preset address pool, a read command is generated, and the I2C bus is scanned for a slave device ACK response signal.

[0009] If an ACK response signal is received from the slave device, the corresponding physical address of the slave device is considered a valid physical address. The scan ends, the valid physical address is written to the memory, and the valid physical address is used to communicate with the I2C device.

[0010] Preferably, in conjunction with the above scheme, if no ACK response signal is received from the slave device, the corresponding physical address of the slave device is an invalid physical address. The invalid physical address is removed from the preset address pool, and the preset address pool is traversed again until the preset address pool is exhausted.

[0011] Preferably, in conjunction with the above scheme, when it is determined that the preset address pool is exhausted, a default physical address is used to communicate with the I2C slave device.

[0012] Preferably, in conjunction with the above scheme, the default physical address is included in the preset address pool, and the default physical address is the physical address of the slave device model with high usage.

[0013] Preferably, in conjunction with the above scheme, the preset address pool contains the physical addresses of slave devices of different models, and is pre-programmed into Flash.

[0014] Preferably, in conjunction with the above scheme, the slave devices' physical addresses are arranged from bottom to top according to the procurement cost of the slave devices.

[0015] Preferably, in conjunction with the above scheme, the physical addresses of the slave devices are arranged from bottom to top according to the difficulty of procuring the slave devices.

[0016] The beneficial effects of this invention are as follows: After integrating automatic addressing logic into the MCU software using this invention, the proximity sensor model communicating with the MCU can be flexibly selected during product design, without being limited to a specific model; during production, the production end does not need to take measures to confirm the proximity sensor model, as the MCU software will automatically adapt to ensure normal function; when costs change and a lower-cost model is desired, there is no need to spend time updating the software or tracking the switch between old and new states, and the switch can be made directly, thereby saving production costs.

[0017] The present invention will now be described in more detail with reference to the accompanying drawings and embodiments. Attached Figure Description

[0018] Figure 1 This is a diagram illustrating an automatic addressing strategy for proximity sensors using an MCU according to the present invention.

[0019] Figure 2 This is a schematic diagram of the MCU traversing the preset physical address pool in this invention.

[0020] Figure 3 Diagram of I2C data link communication protocol (read operation).

[0021] Figure 4 Diagram of I2C data link communication protocol (write operation).

[0022] Figure 5 This is a circuit diagram of the peripheral circuit of the proximity sensor in this invention. Detailed Implementation

[0023] like Figure 5 As shown in the circuit diagram, SENSOR_SDA and SENSOR_SCL are the SDA and SCL lines of the I2C communication bus. An I2C serial bus typically has two signal lines: a bidirectional data line (SDA) and a clock line (SCL). The SDA lines of all devices are connected to the SDA line of the bus, and the SCL lines of each device are connected to the SCL line of the bus. In this invention, the MCU (e.g., model FM33FT023A) acts as the master device, and the proximity sensor (e.g., model VCNL4030X01-GS08) acts as the slave device. The master device accesses a specific slave device through its physical address.

[0024] like Figure 3 and Figure 4 As shown, according to the I2C link layer protocol, when the MCU master device initiates read / write data to the I2C proximity sensor slave device, the first information word of the protocol needs to carry the slave device's physical address and read / write control bit data. When the slave device receives this data, it will compare it with its own physical address. If it is the same as its own physical address, the slave device will send an ACK response bit to the bus.

[0025] like Figure 1 The strategy for automatic addressing of proximity sensors by an MCU, as shown, includes the following steps;

[0026] To ensure fast, efficient, and high-hit-rate traversal, and to reduce the impact of traversal on MCU initialization time, a preset address pool of a certain depth needs to be built in the MCU's Flash memory using a programmer. The preset address pool includes the physical addresses of several slave devices to be traversed. These physical addresses of slave devices are stored in the Flash memory, with each physical address being one byte in size. Assuming sufficient Flash space resources and disregarding the total traversal time, the theoretical range of this preset address pool is 0x01-0xFF, supporting a maximum depth of 255.

[0027] In the addressing process, the MCU master device determines whether a valid physical address exists in the NVM memory.

[0028] If the determination is yes, the MCU master device will use the current valid physical address to communicate with the I2C device.

[0029] If the determination is negative, the MCU master device retrieves the first slave device physical address from the top of the preset address pool. Then, the MCU generates a read instruction, broadcasts it on the I2C bus, and scans the I2C bus for a slave device ACK response signal.

[0030] If the MCU master receives an ACK response signal from the slave device, the current slave device's physical address becomes valid. The scan ends, and the valid physical address corresponding to the slave device's ACK response signal is written to the NVM memory. This valid physical address is then used to communicate with the I2C device. In other words, during subsequent power-up processes, if the MCU master finds a valid physical address already stored in the NVM memory, it will not perform another scan, but will directly retrieve the valid physical address from the NVM memory to communicate with the I2C slave device, further reducing the waste of MCU bus resources caused by multiple scans.

[0031] like Figure 2 As shown, if the MCU master device does not receive an ACK response signal from the slave device, the current slave device physical address is invalid. This invalid address is removed from the preset address pool, and a new round of scanning begins by retrieving the first slave device physical address from the top of the preset address pool. This process iterates through the preset address pool and scans the I2C bus for a slave device ACK response signal until the preset address pool is exhausted. Specifically, when the MCU powers on, it automatically reads the first word (4 bytes) from a fixed address such as 0x00000000. This data serves as the initial value of the stack pointer (SP). After initialization, the stack pointer points to the first slave device physical address in Flash (e.g., stack top 0x01). During subsequent function calls, local variables are allocated from the top of the stack to lower addresses, forming the dynamic usage logic of the stack address.

[0032] To enable the MCU to quickly adapt to common I2C slave devices on the market, the preset address pool contains the physical addresses of slave devices of different models and is pre-programmed into Flash. Common slave device addresses can be pre-collected and added to the preset address pool. During application, the number of physical addresses that the slave device may involve can be collected as the depth of the address pool.

[0033] To avoid MCU address scanning failure due to I2C communication interference, momentary malfunctions of the MCU itself, occasional faults in peripheral circuits, or software bugs, a default physical address can be set in the preset address pool. The default physical address is the slave device physical address of a widely used slave device model on the market, in order to ensure a high communication success rate as much as possible.

[0034] If the preset address pool is exhausted and no ACK response signal is received from the corresponding slave device, the default physical address is used to communicate with the I2C slave device. This default physical address is not written to the NVM memory, so that the preset address pool can be rescanned on the next power-on. After a scan failure, the MCU selects the most commonly used default physical address, and there is a probability that it can still communicate with the slave device after the scan fails.

[0035] Based on the procurement cost of the devices, the physical addresses of the slave devices can be arranged from bottom to top, with the lowest procurement cost placed at the top and the highest at the bottom. This way, each traversal retrieves data from the top of the address pool, and the closer a matching physical address is to the top of the pool, the earlier the traversal ends. This makes the traversal fast, efficient, and with a higher hit rate.

[0036] Based on the difficulty of procuring the devices, the physical addresses of the slave devices can be arranged from bottom to top, with the easiest devices placed at the top and the most difficult at the bottom. Each iteration retrieves data from the top of the address pool; the closer the waiting physical address is to the top of the address pool, the earlier the iteration ends. This effectively reduces the impact of iteration on MCU initialization time.

[0037] Of course, the physical addresses of slave devices can also be arranged from bottom to top based on the procurement cost and difficulty of the equipment. That is, the physical addresses of slave devices with the lowest procurement cost and difficulty are arranged at the top, while those with the highest procurement cost and difficulty are arranged at the bottom.

[0038] In the description of this invention, it should be understood that terms such as "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this invention, unless otherwise stated, "a plurality of" means two or more.

[0039] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art will understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0040] The present invention has been described above with reference to the accompanying drawings. Obviously, the specific implementation of the present invention is not limited to the above-described manner. Any improvements made using the inventive concept and technical solution of the present invention, or direct application to other situations without modification, fall within the protection scope of the present invention.

Claims

1. A strategy for automatic addressing of proximity sensors by an MCU, characterized in that, Includes steps; A preset address pool is constructed within the Flash memory, the preset address pool including several slave device physical addresses that need to be traversed; Start addressing to determine if a valid physical address exists in the memory; If the determination is yes, then the current valid physical address is used to communicate with the I2C device; If the determination is negative, the first slave device physical address is retrieved from the top of the preset address pool, a read command is generated, and the I2C bus is scanned for a slave device ACK response signal. If an ACK response signal is received from the slave device, the corresponding physical address of the slave device is considered a valid physical address. The scan ends, the valid physical address is written to the memory, and the valid physical address is used to communicate with the I2C device.

2. The strategy for automatic addressing of proximity sensors by the MCU according to claim 1, characterized in that, If no ACK response signal is received from the slave device, the corresponding physical address of the slave device is an invalid physical address. The invalid physical address is removed from the preset address pool, and the preset address pool is traversed again until it is exhausted.

3. The strategy for automatic addressing of proximity sensors by the MCU according to claim 2, characterized in that, When the preset address pool is exhausted, a default physical address is used to communicate with the I2C slave device.

4. The strategy for automatic addressing of proximity sensors by the MCU according to claim 3, characterized in that, The default physical address is included in the preset address pool, and the default physical address is the physical address of the slave device model with high usage.

5. The strategy for automatic addressing of proximity sensors by the MCU according to claim 1, characterized in that, The preset address pool contains the physical addresses of slave devices of different models and is pre-programmed into Flash.

6. The strategy for automatic addressing of proximity sensors by the MCU according to claim 5, characterized in that, Based on the procurement cost of the equipment, the slave devices are arranged from bottom to top by their physical addresses.

7. The strategy for automatic addressing of proximity sensors by the MCU according to claim 5, characterized in that, Based on the difficulty of procuring the equipment, the slave devices' physical addresses are arranged from bottom to top.

Citation Information

Cited By

  • Method and system for instrument to automatically identify multiple electrodes

    CN121298829A

  • Hardware development integration method and device

    CN121387805A