请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:BQ76972 工具/软件:
TI 团队大家好、
我已附加 I2C 扫描器件代码、该代码用于扫描连接在 I2C 通道上的器件。 但如果我在同一通道上写入数据、则不起作用
谢谢您、
// To find the device address // void I2C_ScanBus() { char msg[64]; uint8_t devicesFound = 0; for (uint8_t address = 1; address < 127; address++) { HAL_GPIO_WritePin(MCU_BMS_RESET_GPIO_Port, MCU_BMS_RESET_Pin, GPIO_PIN_SET); HAL_Delay(100); HAL_GPIO_WritePin(MCU_BMS_RESET_GPIO_Port, MCU_BMS_RESET_Pin, GPIO_PIN_RESET); HAL_Delay(100); if (HAL_I2C_IsDeviceReady(&hi2c3, address << 1, 3, 10) == HAL_OK) { snprintf(msg, sizeof(msg), "Found I2C device at 0x%02X\r\n", address << 1); RS485_Transmit((uint8_t*)msg, strlen(msg)); devicesFound++; } } if (devicesFound == 0) { RS485_Transmit((uint8_t*)"No I2C devices found\r\n", 23); } }