2008-09-23 05:13 PM
2008-07-24 04:11 AM
I'm trying to activate I2C module on STR750 with the code below.
I can't manage to generate start and I get to wait forever for Busy status bit. Can any help ? Attached code; #include ''75x_mrcc.h'' #include ''75x_i2c.h'' int I2CDriverInit(void) { I2C_InitTypeDef I2C_InitStruct; GPIO_InitTypeDef GPIO_InitStructure; /* Initialize pins - STR750 reference manual page 86*/ /* Configure the I2C SCL alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure the I2C SDA as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_Init(GPIO0, &GPIO_InitStructure); GPIO_WriteBit(GPIO0, GPIO_Pin_8, Bit_RESET); GPIO_WriteBit(GPIO0, GPIO_Pin_9, Bit_RESET); GPIO_WriteBit(GPIO0, GPIO_Pin_8, Bit_SET); GPIO_WriteBit(GPIO0, GPIO_Pin_9, Bit_SET); /* Configure the UART2_Tx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure the UART2_Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_Init(GPIO0, &GPIO_InitStructure); GPIO_WriteBit(GPIO0, GPIO_Pin_8, Bit_SET); GPIO_WriteBit(GPIO0, GPIO_Pin_9, Bit_SET); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure the I2C SDA as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_Init(GPIO0, &GPIO_InitStructure); GPIO_WriteBit(GPIO0, GPIO_Pin_8, Bit_SET); GPIO_WriteBit(GPIO0, GPIO_Pin_9, Bit_SET); /* Configure the UART2_Tx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure the UART2_Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_Init(GPIO0, &GPIO_InitStructure); /* enable HW */ /* reset HW */ I2C_DeInit(); /* Enable the I2C Clock. */ MRCC_PeripheralClockConfig( MRCC_Peripheral_I2C, ENABLE ); /* init I2C structure */ I2C_StructInit(&I2C_InitStruct); /* I2C initialization */ I2C_InitStruct.I2C_GeneralCall = I2C_GeneralCall_Disable; I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; I2C_InitStruct.I2C_CLKSpeed = I2CSPEED; I2C_InitStruct.I2C_OwnAddress = I2COWNADDR; I2C_Cmd(ENABLE); /* init I2C HW */ I2C_Init(&I2C_InitStruct); return 0; } test() { /* generate start condition */ I2C_GenerateSTART(ENABLE); /* test on EV5 and clear it */ rprintf(''W 4 5\n''); I2CEventCheck(I2C_EVENT_MASTER_MODE_SELECT); /* send EEPROM address for read */ rprintf(''S A %x\n'', *ptr); I2C_Send7bitAddress(*ptr, I2C_MODE_RECEIVER); /* test on EV6 and clear it */ rprintf(''W 4 6\n''); I2CEventCheck(I2C_EVENT_MASTER_MODE_SELECTED); /* clear EV6 by setting again the PE bit */ I2C_Cmd(ENABLE); } main() { int I2CDriverInit(void); test(); }2008-09-23 05:13 PM
I think your call to I2C_Send7bitAddress should have I2C_MODE_TRANSMITTER.
I2C_Send7bitAddress(*ptr, I2C_MODE_TRANSMITTER);