Hi JE_Dialog,
Could you please give me the document related to I2C communication using interrupt?
If there is not an official document, you can answer the following questions for me:
1. How to enable I2C interrupt mode operation? (master mode)
2. How to read the status code of I2C communication?
3. Please, show me about the format and states in the Master Transmitter and Receiver mode.
4. Please, give me a small example code like that:
空白I2C_IRQHandler (void)
{
uint8_t StatValue;timeout = 0;
/* this handler deals with master read and master write only */
StatValue = LPC_I2C->STAT;
switch ( StatValue )
{
case 0x08: /* A Start condition is issued. */
WrIndex = 0;
LPC_I2C->DAT = I2CMasterBuffer[WrIndex++];
LPC_I2C->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
break;case 0x10: /* A repeated started is issued */
RdIndex = 0;
/* Send SLA with R bit set, */
LPC_I2C->DAT = I2CMasterBuffer[WrIndex++];
LPC_I2C->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
break;case 0x18: /* Regardless, it's a ACK */
if ( I2CWriteLength == 1 )
{
LPC_I2C->CONSET = I2CONSET_STO; /* Set Stop flag */
I2CMasterState = I2C_NO_DATA;
}
else
{
LPC_I2C->DAT = I2CMasterBuffer[WrIndex++];
}
LPC_I2C->CONCLR = I2CONCLR_SIC;
break;case 0x28: /* Data byte has been transmitted, regardless ACK or NACK */
if ( WrIndex < I2CWriteLength )
{
LPC_I2C->DAT = I2CMasterBuffer[WrIndex++]; /* this should be the last one */
}
else
{
if ( I2CReadLength != 0 )
{
LPC_I2C->CONSET = I2CONSET_STA; /* Set Repeated-start flag */
}
else
{
LPC_I2C->CONSET = I2CONSET_STO; /* Set Stop flag */
I2CMasterState = I2C_OK;
}
}
LPC_I2C->CONCLR = I2CONCLR_SIC;
break;case 0x30:
LPC_I2C->CONSET = I2CONSET_STO; /* Set Stop flag */
I2CMasterState = I2C_NACK_ON_DATA;
LPC_I2C->CONCLR = I2CONCLR_SIC;
break;case 0x40: /* Master Receive, SLA_R has been sent */
if ( (RdIndex + 1) < I2CReadLength )
{
/* Will go to State 0x50 */
LPC_I2C->CONSET = I2CONSET_AA; /* assert ACK after data is received */
}
else
{
/* Will go to State 0x58 */
LPC_I2C->CONCLR = I2CONCLR_AAC; /* assert NACK after data is received */
}
LPC_I2C->CONCLR = I2CONCLR_SIC;
break;case 0x50: /* Data byte has been received, regardless following ACK or NACK */
I2CSlaveBuffer[RdIndex++] = LPC_I2C->DAT;
if ( (RdIndex + 1) < I2CReadLength )
{
LPC_I2C->CONSET = I2CONSET_AA; /* assert ACK after data is received */
}
else
{
LPC_I2C->CONCLR = I2CONCLR_AAC; /* assert NACK on last byte */
}
LPC_I2C->CONCLR = I2CONCLR_SIC;
break;case 0x58:
I2CSlaveBuffer[RdIndex++] = LPC_I2C->DAT;
I2CMasterState = I2C_OK;
LPC_I2C->CONSET = I2CONSET_STO; /* Set Stop flag */
LPC_I2C->CONCLR = I2CONCLR_SIC; /* Clear SI flag */
break;case 0x20: /* regardless, it's a NACK */
case 0x48:
LPC_I2C->CONSET = I2CONSET_STO; /* Set Stop flag */
I2CMasterState = I2C_NACK_ON_ADDRESS;
LPC_I2C->CONCLR = I2CONCLR_SIC;
break;case 0x38: /* Arbitration lost, in this example, we don't
deal with multiple master situation */
default:
I2CMasterState = I2C_ARBITRATION_LOST;
LPC_I2C->CONCLR = I2CONCLR_SIC;
break;
}
return;
}
Best regards,
Can you help me?
Hello Mir Ali, the only example we have right now is the peripheral driver example in UM-B-005 of standard i2c read/write commands to EEPROM. We have a couple of acceleromter apps in development, but they are a few weeks away from being finsihed.
I will get one of the software team to take a look at your question but it will be a couple of days.
BR JE_Dialog
Hi Ali,
I think the code you copied from NXP is using some kind of software I2C. Means it generate interrupt for each status of I2C communication and need to adding code in the ISR to handle the status machine of I2C communication. Actually Dialog provide full hardware I2C support so you can see from our datasheet the status machine has already be implemented in HW, both slave and master. So it will easier for your use of I2C in DA14580, you don't need to care about the dirty job of handling status changing, just write or grab bytes on certain address with several lines of code.
You can refer to the DA14580_peripheral example code, there you can get the example code, more simple than software I2C.
Regards!
PY
Hi PY,
I think i dont understand something. How can the DA14580 be a I2C slave and do other stuff as well if you have to actively check the hardware registers. I think i don't understand how interrupts are used in general by the DA14580
King regards,
Naoufal
Hi Naoufal,
Ali's code is target for master mode I2C. And I think you are asking for slave mode I2C right? Actually few people will use our I2C in slave mode though we can support slave mode state machine. So there is no document or reference code on slave mode I2C for the moment. I will suggest you choose Uart or SPI instead if possible.
Regards!
PY
hi,dialog
In the I2C slave mode, how to start the interrupt? Which registe note enable the interrupt?