/* I2C Peripheral Enable */ I2C_Cmd(I2C2, ENABLE); /* Enable I2C2 event interrupt */ I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF , ENABLE); /* Apply I2C configuration after enabling it */ I2C_Init(I2C2, &I2C_InitStructure); /* While the bus is busy */ while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
Delay(0x7FFFF);
DS2482_reset();
int DS2482_reset() { u8 status; u8 str[4]; // Device Reset // S AD,0 [A] DRST [A] Sr AD,1 [A] [SS] A\ P // [] indicates from slave // SS status byte to read to verify state
I2C_GenerateSTART(I2C2, ENABLE);
/* Send address for write */ I2C_Send7bitAddress(I2C2,I2C_1wirereadaddr , I2C_Direction_Transmitter);
status = I2C_ReceiveData(I2C2); UTIL_int2str(str,status,2,0); I2C_GenerateSTOP(I2C2, ENABLE); DRAW_DisplayString(0,0,str,2);
// check for failure due to incorrect read back of status return ((status & 0xF7) == 0x10); }
I keep getting a response of 0x05 displayed. Using my Logic device, I can see only the DS2482 power up pin getting toggled and SDA line going low shortly after. Attached a pic of that action. Please help! Thanks!
Wanted to provide another symptom to my problem. If I change I2C2 to I2C1 and some other posts on here suggest, the SDA line toggles low at the same time as my last post but toggles back high 1.24uS later and stays high. Any help would be greatly appreciated. Thanks!
I think your problem can be you are not waiting for the hardware to be finished before you make the next I2C command...
You must wait until the hardware is ready...
I have some old prelim code for an touch sensor i want to give you, be aware there is a lot of commented lines there proberly is not needed, but i think you can se the point with the while loops...
Copy the code to an editor for better view....
Kasper
Code:
unsigned char touch_RD(unsigned char addr,unsigned char count)
{
unsigned char values[65],i;
/*----- First transmission Phase -----*/
/* Send I2C1 START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send I2C2 slave Address for write */
I2C_Send7bitAddress(I2C1, SLAVE_ADDRESS7, I2C_Direction_Transmitter);
/* Test on I2C2 EV1 and clear it */
//while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED));
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Send data */
/* Send I2C1 data */
I2C_SendData(I2C1, addr);
/* Send I2C1 STOP Condition */
I2C_GenerateSTOP(I2C1, ENABLE);
DelayMs(10);
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send I2C2 slave Address for write */
I2C_Send7bitAddress(I2C1, SLAVE_ADDRESS7, I2C_Direction_Receiver);
/* Test on I2C1 EV8 and clear it */
// while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
for(i=0;i<count-1;i++)
{
/* Test on I2C2 EV2 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
/* Store received data on I2C2 */
values[i] = I2C_ReceiveData(I2C1);
}
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C1, DISABLE);
/* Send I2C1 STOP Condition */
I2C_GenerateSTOP(I2C1, ENABLE);
/* Test on I2C2 EV2 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
/* Store received data on I2C2 */
values[++i] = I2C_ReceiveData(I2C1);
/* Test on I2C2 EV4 and clear it */
// while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_STOP_DETECTED));
for(i=0;i<12;i+=2)
{
temp = values[i+41];
temp<<=8;
temp |= values[i+40];
printf("%u--", temp);
}
printf("%u--", values[4]); */
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C1,ENABLE);
return values[4];
}
Thanks for the reply, but still stuck. Started looking in the Circle OS files to see what could be going on and found that the audio device uses the I2C2 label instead of I2C1. I used that code as a guideline to try but still no luck either. I've tried disabling Timer2 as suggested in another post but still no go. Has anyone been able to use the I2C2 labeled external I2C port at all? Please help! Thanks!
Thanks for the reply. Shouldn't I still be seeing SDA and SCL action using my Logic analyser as I've displayed in my other post? SCL never toggles and SDA only toggles once after I power up the DS2482 device. Thanks!