Learn MoreFAQsTutorials

4个帖子/ 0新
Last post
Ahiggs.
Offline
最后一次露面:4 months 3 weeks ago
Joined:2019-12-17 07:10
多个I2C总线

Hello,

我对DA14585上的多个I2C总线有所了解。我正在使用MCP9600热电偶放大器,每个放大器每个都有8个可能的地址。我需要将这些传感器中的64个连接到DA14585,并在〜1Hz读取它们。

我的计划是设置8个单独的总线,每个总线都有自己的数据线和一个共享时钟(在DA14585上使用总共9个引脚)。DA14585将基于它想要与该总线完成的哪些总线进行配置的I2C控制器,让数据线保持高。从I2C的角度来看,非活动总线上的芯片会看到常量1的总线时,当它们的总线未激活时,这对于其他配置是优选的,其中每个配置都有其自己的时钟,并且芯片看到恒定的停止/启动命令。

The only thing I am not sure of is how to accomplish this in the code. I would like to set it up like this so that way I can switch through the busses. Is the RESERVE_GPIO() command necessary, or would that confuse things? Otherwise I assume this would work

void init_mcp(void){letail_gpio(,all_scl_port,all_scl_pin,pid_i2c_scl);保留_gpio(,bus1_sda_port,bus1_sda_pin,pid_i2c_sda); // ????保留_gpio(,bus2_sda_port,bus2_sda_pin,pid_i2c_sda); // ????剩余的引脚... gpio_configurepin(all_scl_port,all_scl_pin,输入,pid_i2c_scl,false);void select_mcp_bus(uint8_t bus_number){switch bus_number:case 1:gpio_configurepin(bus1_sda_port,bus1_sda_pin,输入,pid_i2c_sda,false);for(所有其他总护)GPIO_CONFIGUREPIN(BUS1_SDA_PORT,BUS1_SDA_PIN,INPUT,PID_GPIO,FALSE);休息;案例2:gpio_configurepin(bus2_sda_port,bus2_sda_pin,输入,pid_i2c_sda,false);for(所有其他总护)GPIO_CONFIGUREPIN(BUS1_SDA_PORT,BUS1_SDA_PIN,INPUT,PID_GPIO,FALSE);休息; case 3: remaining busses... } void send_temperature(){ for(all 8 busses){ select_MCP_BUS(bus#) for(all 8 MCPs){ sample_send_temp(MCP#) } } }

我知道我可以使用一个i2c mux来完成这一点,但我们的空间有限,它只是一个可能失败的额外组件

设备:
PM_DIALOG.
Offline
最后一次露面:29 min 15 sec ago
Staff
Joined:2018-02-08 11:03
Hi ahiggs,

Hi ahiggs,

谢谢你的问题在线和德泰led description. We haven’t such an example demonstrating the described functionality, but this might be a possible approach. Every time that you would like to change the “BUS_NUMBER”, you should re-configure the appropriate GPIO as I2C pin. Did you test this on your HW setup?

谢谢,PM_DIALOG.

Ahiggs.
Offline
最后一次露面:4 months 3 weeks ago
Joined:2019-12-17 07:10
Hello,

Hello,

Thanks for your prompt reply. I have only tested the hardware setup with MCP9600s on one of the buses but it worked. I have not yet designed the boards to test the full system. If anyone is interested, here's a snippet of code for this setup

void sensor_init(){adc_calibrate();adc_timer [0] = app_easy_timer(adc_timer_delay [0],readadc0);//检查定时器是否可用(int a = 0; a <1; a ++){if(adc_timer [a] ==yeasy_timer_invalid_timer){whis(1); // badbadbad}} // for mcp放大器:boolinit_error = false;READ_ADC [0] = 1;init_i2c();for(Uint8_t i = 0; i <1; i ++){//初始化1总线(8 max)set_i2c_bus(i + 1); // 1索引(UInt8_t a = 0; <2; a ++){//初始化2个传感器((8 max)IF(!init_mcp(a))// 0索引init_rure;}}}}}}}}}}}} void init_i2c(void){//初始化mcp芯片gpio_configurepin的i2c总线(i2c_scl_port,i2c_scl_pin,input_pullup,pid_i2c_scl,false); //不要配置SDA PIN you} void set_i2c_bus(uint8_t总线){//选择哪些数据线用于i2c //从pid_i2c_sda //释放其他引脚,我认为这可能是更清晰的使用最后一个引脚被跟踪...... GPIO_ConfigurePin(I2C_SDA1_PORT,I2C_SDA1_PIN,INPUT,PID_GPIO,FALSE); GPIO_ConfigurePin(I2C_SDA2_PORT,I2C_SDA2_PIN,INPUT,PID_GPIO,FALSE); GPIO_ConfigurePin(I2C_SDA3_PORT,I2C_SDA3_PIN,INPUT,PID_GPIO,FALSE); GPIO_ConfigurePin(I2C_SDA4_PORT,I2C_SDA4_PIN,INPUT,PID_GPIO,FALSE); GPIO_CONFIGUREPIN(I2C_SDA5_POR,I2C_SDA5_PIN,INPUT,PID_GPIO,FALSE); GPIO_CONFIGUREPIN(I2C_SDA6_PORT,I2C_SDA6_PIN,INPUT,PID_GPIO,FALSE); GPIO_CONFIGUREPIN(I2C_SDA7_PORT,I2C_SDA7_PIN,INPUT,PID_GPIO,FALSE); GPIO_ConfigurePin(I2C_SDA8_PORT, I2C_SDA8_PIN, INPUT, PID_GPIO, false); //set the new bus pin to PID_I2C_SDA switch(bus){ case 1: GPIO_ConfigurePin(I2C_SDA1_PORT, I2C_SDA1_PIN, INPUT, PID_I2C_SDA, false); break; case 2: GPIO_ConfigurePin(I2C_SDA2_PORT, I2C_SDA2_PIN, INPUT, PID_I2C_SDA, false); break; case 3: GPIO_ConfigurePin(I2C_SDA3_PORT, I2C_SDA3_PIN, INPUT, PID_I2C_SDA, false); break; case 4: GPIO_ConfigurePin(I2C_SDA4_PORT, I2C_SDA4_PIN, INPUT, PID_I2C_SDA, false); break; case 5: GPIO_ConfigurePin(I2C_SDA5_PORT, I2C_SDA5_PIN, INPUT, PID_I2C_SDA, false); break; case 6: GPIO_ConfigurePin(I2C_SDA6_PORT, I2C_SDA6_PIN, INPUT, PID_I2C_SDA, false); break; case 7: GPIO_ConfigurePin(I2C_SDA7_PORT, I2C_SDA7_PIN, INPUT, PID_I2C_SDA, false); break; case 8: GPIO_ConfigurePin(I2C_SDA8_PORT, I2C_SDA8_PIN, INPUT, PID_I2C_SDA, false); break; } } bool init_MCP(uint8_t addr){ user_i2c_init(0x60+addr, I2C_7BIT_ADDR, I2C_STANDARD, I2C_1BYTE_REGISTER, I2C_1BYTE_ADDR); //device config register, 0.0625°C ambient accuracy, 18-bit, 1 sample, shutdown mode: 0b00000001 (highest accuracy settings) if(i2c_write_2byte_MCP(0x06, 0x02)!=I2C_NO_ERROR) return 0; //initialize next sample: device status register 0x04, clear bit7 to start sample, other bits can be cleared too if(i2c_write_2byte_MCP(0x04, 0x00)!=I2C_NO_ERROR) return 0; SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller SetBits16(CLK_PER_REG, I2C_ENABLE, 0); // Disable clock for I2C return 1; } uint16_t read_MCP(uint8_t addr){//read the MCP, assuming the temperature is ready user_i2c_init(0x60+addr, I2C_7BIT_ADDR, I2C_STANDARD, I2C_1BYTE_REGISTER, I2C_1BYTE_ADDR); uint16_t value=0; //device config register, 0.0625°C ambient accuracy, 18-bit, 1 sample, shutdown mode: 0b00000001 (highest accuracy settings) if(i2c_write_2byte_MCP(0x06, 0x02)!=I2C_NO_ERROR) return 0; //select register to read by first writing to select it: 0x00 for hot, 0x02 for cold(chip) temperature if(i2c_write_byte_MCP(0x00)!=I2C_NO_ERROR) value=0xFFFF; //read the two bytes from the register if(i2c_read_2byte_MCP(&value)!=I2C_NO_ERROR) value=0xFFFF; //initialize next sample: device status register, clear bit7 to start sample, other bits can be cleared too if(i2c_write_2byte_MCP(0x04, 0x00)!=I2C_NO_ERROR) value=0xFFFF; SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller SetBits16(CLK_PER_REG, I2C_ENABLE, 0); // Disable clock for I2C return value;//right shift by 4 to get integer temperature (or do temp °C = MSB*16+LSB/16 if greater than 0) } #define I2C_SCL_PORT GPIO_PORT_0//pin 1 on QFN40 chip #define I2C_SCL_PIN GPIO_PIN_0 #define I2C_SDA1_PORT GPIO_PORT_0//pin 2 on QFN40 chip #define I2C_SDA1_PIN GPIO_PIN_1 #define I2C_SDA2_PORT GPIO_PORT_0//pin 3 on QFN40 chip #define I2C_SDA2_PIN GPIO_PIN_2 #define I2C_SDA3_PORT GPIO_PORT_0 #define I2C_SDA3_PIN GPIO_PIN_3 #define I2C_SDA4_PORT GPIO_PORT_2//would use P0_4, but used by UART #define I2C_SDA4_PIN GPIO_PIN_0 #define I2C_SDA5_PORT GPIO_PORT_3 #define I2C_SDA5_PIN GPIO_PIN_0 #define I2C_SDA6_PORT GPIO_PORT_2//would use P0_5 but used by UART #define I2C_SDA6_PIN GPIO_PIN_9 #define I2C_SDA7_PORT GPIO_PORT_2 #define I2C_SDA7_PIN GPIO_PIN_1 #define I2C_SDA8_PORT GPIO_PORT_1//would use P0_6 but used by UART #define I2C_SDA8_PIN GPIO_PIN_2

PM_DIALOG.
Offline
最后一次露面:29 min 15 sec ago
Staff
Joined:2018-02-08 11:03
Hi ahiggs,

Hi ahiggs,

Thanks for your inputs. If you have any other question, please raise a new forum thread.

谢谢,PM_DIALOG.