最近在调STM32F411RET的硬件IIC2,复用PB9 PB10为IIC2,但是一直读不到模块寄存器的值,望大神指点,万分感谢 IIC初始化如下: void iic_Init(void) { //I2C_HandleTypeDef I2CxHandle; I2CxHandle.Instance=I2C2; I2CxHandle.Init.AddressingMode=I2C_ADDRESSINGMODE_7BIT; I2CxHandle.Init.ClockSpeed=100000; I2CxHandle.Init.DualAddressMode=I2C_DUALADDRESS_DISABLE; I2CxHandle.Init.DutyCycle=I2C_DUTYCYCLE_2; I2CxHandle.Init.GeneralCallMode=I2C_GENERALCALL_DISABLE; I2CxHandle.Init.NoStretchMode=I2C_NOSTRETCH_DISABLE; I2CxHandle.Init.OwnAddress1=0;//0x69; I2CxHandle.Init.OwnAddress2=0;//0x68; HAL_I2C_Init(&I2CxHandle); } MSP的初始化如下: void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) { GPIO_InitTypeDef GPIO_InitStruct; __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_I2C2_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = GPIO_AF4_I2C2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = GPIO_AF4_I2C2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } 读取模块的寄存器的值:模块的设备地址为0x34 ,0x3D为模块的寄存器 HAL_I2C_Mem_Read(&I2CxHandle, 0x34, 0x3D, I2C_MEMADD_SIZE_8BIT, &DATA, 1, 10); |
不错顶一个 |
我记得好像是用 HAL_I2C_Master_Receive来读的吧。
|
STM32F407 定时器触发DMA 求助大神
【MCU实战经验】基于STM32F407的音频播放器设计
盘古UE-STM32F407工控板原理图
【STM32F429心得\疑问】+STM32F4之FSMC和FMC
STM32F429读取IO口传输的数据速率
STM32F407ZGT6 手摸芯片背部重启
STM32F4 SPI 动作时,软件片选信号被拉高,IO口程序逻辑失控
STM32F401RE NUCLEO求助,串口一直不能进中断
读取STM32F407内部温度传感器值错误
STM32F429多路内部ADC独立采集的办法