AnsweredAssumed Answered

comunication between color sensor and stm8s-discovery with i2c

Question asked by danielina.marina on Feb 1, 2011
Latest reply on Feb 2, 2011 by brazov.ajeje
Hi!
I want that stm8s-discovery read color  using a color sensor (ADJD-S371-QR999).
I use i2c protocol in this way:

I2C_GenerateSTART(ENABLE);
    while(!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));</span></div>
     // i want to read data from color sensor (0x74)
  I2C_Send7bitAddress(0x74, I2C_DIRECTION_RX);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
while (Rx_Idx < RX_BUFFERSIZE)
{
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
I2C_Buffer_Rx[Rx_Idx++] = I2C_ReceiveData();
}

//nack.... in this point, master have to send a NACK to sensor in order to finish the i2c protocol.
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE); </span></div>
 I2C_GenerateSTOP(ENABLE);

I don't Know if this is the correct method to send NACK and moreover i not sure that the implementation of protocol is right.
I need help, please!
Thank you!


Outcomes