The use of tca9548 under embedded Linux and the example of measuring sensor.

tca9548 is an IIC expansion board, which is mainly used in the measurement environment of multiple sensors of the same type. It is ensured that the sensor can also be measured with the same factory address. . . Let's start with the entire usage steps

First of all, it must be ensured that the development board kernel has an IIC driver; if there is no driver in the development board kernel, please refer to http://www.alliedjeep.com/132698.htm to write the relevant driver to the kernel. This article mainly concerns the writing process of the user program.

Step1: Hardware wiring, tca9548 is an IIC expansion board, and itself is an IIC device, including SCL, SDA, and power VCC, ground GND. It also includes A0, A1, A2, three address selection pins. SCL, SDA, and power supply VCC, ground GND are connected to the corresponding pins of the development board, A0, A1, A2 can be grounded or power supply, when it is grounded, the address is 0x70, and when it is connected to the power supply at the same time, it is 0x77.

    Also connect the required sensors to the tca9548.

Step2; programming steps

        Initialize tca9548, including opening the device file and setting the slave address to the address of pca9548;

        Write commands to tca9548, select the channel, and determine which sensor to measure;

        Initialize the sensor, turn on the sensor, and set the slave address to the sensor address again.

        The above steps are looped for measurement.

The main function is as follows: Remember to re-initialize the pca9548 every time the sensor is changed for measurement. If the initialization is not performed, the measured data will be the data of the first initialized sensor, and the data of other sensors will not be measured.

int main(int argc, char *argv[])
{int i;while(1){for(i=0;i<8;i++){PCA_Init();i2c_write(fd,PCA_ADDR,Channel_selection[i]);  MAG_Init();printf("init success!\n");printf("**************Channel_selection:%6d\n",i);printf("this time is printing :%d\n",Channel_selection[i]);//while(1)//{usleep(1000*200);printf("ACCE_MX:%6d\n ",GetData(OUT_X_MSB));printf("ACCE_LX:%6d\n ",GetData(OUT_X_LSB));printf("ACCE_MY:%6d\n ",GetData(OUT_Y_MSB));printf("ACCE_LY:%6d\n ",GetData(OUT_Y_LSB));printf("ACCE_MZ:%6d\n ",GetData(OUT_Z_MSB));printf("ACCE_LZ:%6d\n ",GetData(OUT_Z_LSB));









 

















printf("it's ok!!\n");
}
}close(fd);  

}

If you need the entire source code, you can contact [email protected]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325966162&siteId=291194637