I2C上拉电阻问题分析(基于stm32 HAL库)
在使用stm32读写 ST温湿度hts221时,使用I2C总线,总线上还挂在了别的传感器,发现有时候可以读出数据,有时候读不出数据,一直是0。
首先,stm32 配置I2C IO时,使用的是AF_OD,即使用复用开漏输出,这也是官方I2C所要的方式,电流电压取决于外部电路。同时IO也配置了内部上拉。
/**
* @brief I2C MSP Initialization
* This function configures the hardware resources used in this example:
* - Peripheral's clock enable
* - Peripheral's GPIO Configuration
* - DMA configuration for transmission request by peripheral
* - NVIC configuration for DMA interrupt request enable
* @param hi2c: I2C handle pointer
* @retval None
*/
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_PeriphCLKInitTypeDef RC