有人调过么,主机买了一个usb转i2c的东西用pc调试,试了下主机发出来的波形是对的,但是从机进不了中断。
初始化的代码
GPIO_InitTypeDef gpioInitStruct;
I2C_InitTypeDef i2cInitStructure;
NVIC_InitTypeDef nvicInitStructure;
// Enable clock gpiob
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
// Enable clock i2c1
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
I2C_DeInit(I2C1);
// Set interrupt
nvicInitStructure.NVIC_IRQChannel = I2C1_EV_IRQn;
nvicInitStructure.NVIC_IRQChannelPreemptionPriority = 1;
nvicInitStructure.NVIC_IRQChannelSubPriority = 0;
nvicInitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicInitStructure);
nvicInitStructure.NVIC_IRQChannel = I2C1_ER_IRQn;
nvicInitStructure.NVIC_IRQChannelPreemptionPriority = 0;
nvicInitStructure.NVIC_IRQChannelSubPriority = 0;
nvicInitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicInitStructure);
//Set gpio
gpioInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
gpioInitStruct.GPIO_Mode = GPIO_Mode_AF_OD;
gpioInitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_Init(GPIOB, &gpioInitStruct);
i2cInitStructure.I2C_Mode = I2C_Mode_I2C;
i2cInitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
i2cInitStructure.I2C_Ack = I2C_Ack_Enable;
i2cInitStructure.I2C_OwnAddress1 = 0x30;///////////////??????
i2cInitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
i2cInitStructure.I2C_ClockSpeed = 200000;/////?????????????
I2C_Init(I2C1, &i2cInitStructure);
I2C_ITConfig(I2C1, I2C_IT_EVT|I2C_IT_BUF|I2C_IT_ERR, ENABLE);
I2C_Cmd(I2C1, ENABLE); |