void I2C_ADS1110_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure; /* GPIOB Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO |
RCC_APB2Periph_GPIOB, ENABLE);
/* I2C1 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
/* Configure I2C1 pins: SCL and SDA */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
I2C_DeInit(I2C2);
/* I2C1 Init */
// I2C_GeneralCallCmd(I2C2,DISABLE);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 200000;
I2C_Init(I2C2, &I2C_InitStructure);
/* I2C1 Init */
I2C_Cmd(I2C2, ENABLE);
}
/*******************************************************************************
* Function Name : I2C_LM75_ConfReg_Write
* Description : Write to the configuration register of the LM75.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ADS1110_ConfReg_Write(u8 RegValue)
{
/*----- Transmission Phase -----*/
/* Send I2C1 START condition */
I2C_GenerateSTART(I2C2, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)) /* EV5 */
{
}
/* Send STLM75 slave address for write */
I2C_Send7bitAddress(I2C2, ADS1110_ADDR, I2C_Direction_Transmitter);
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
{
}
// /* Send the configuration register data pointer */
// I2C_SendData(I2C2, 0x9c);
//
// /* Test on I2C1 EV8 and clear it */
// while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
// {
// }
/* Send I2C1 data */
I2C_SendData(I2C2, RegValue);
/* Test on I2C1 EV8 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
{
}
/* Send I2C1 STOP Condition */
I2C_GenerateSTOP(I2C2, ENABLE);
}
最近调一个ADS1110,借用例程里面LM75的配置,现在发现红色代码部分一直处于循环状态,请大家帮忙分析一下。 |