在开发板的基础上,自己做了一块基于STM32F407IG的电路板,EEPROM采用的是AT24C256,I2C采用的是I2C2(PH4和PH5),现在SCL有信号,SDA管脚没有信号,配置程序如下;其他的程序采用的正点原子的程序, 请问,可能哪里出问题啦?初学ARM,请多多指教。
#define SDA_IN() {GPIOH->MODER&=~(3<<(5*2));GPIOB->MODER|=0<<5*2;} //PH5êäèëÄ£ê½
#define SDA_OUT() {GPIOH->MODER&=~(3<<(5*2));GPIOB->MODER|=1<<5*2;} //PH5êä3öÄ£ê½
#define IIC_SCL PHout(4) //SCL
#define IIC_SDA PHout(5) //SDA
#define READ_SDA PHin(5) //
void GPIO_IIC_Config(void)
{
GPIO_InitTypeDef GPIO_InitIICStruct;
I2C_InitTypeDef I2C_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); //Enable peripheral clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitIICStruct.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitIICStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitIICStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitIICStruct.GPIO_OType = GPIO_OType_OD;
GPIO_InitIICStruct.GPIO_PuPd = GPIO_PuPd_DOWN;//GPIO_PuPd_NOPULL;
GPIO_Init(GPIOH, &GPIO_InitIICStruct);
GPIO_PinAFConfig(GPIOH,GPIO_PinSource4,GPIO_AF_I2C2);
GPIO_PinAFConfig(GPIOH,GPIO_PinSource5,GPIO_AF_I2C2);
I2C_DeInit(I2C2);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0xA0; ·
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = (100 * 1000); //SCL×î′ó100KHz
I2C_Cmd(I2C2, ENABLE);
I2C_Init(I2C2, &I2C_InitStructure);
I2C_AcknowledgeConfig(I2C2, ENABLE);
I2C2->CR1 |= 1<<7;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>