AnsweredAssumed Answered

STM32F4 + EEPROM + I2C interrupts

Question asked by hosS on Apr 22, 2013
Hi
I am trying to read 4 consecutive registers from an EEPROM using I2C through interrupts. The Start Generation is done inside an EXTI interrupt handler after the user button is Pressed. The rest of the reading sequence is done inside the I2C IRQ Handler. 
When I press the user button for the first time, everything works fine, but when I press it a second time only the first register is read and the EEPROM internal address counter does not increment. Here is the sequence inside the I2C_IRQ handler below.
I think the problem is related to the acknowledge by the end of the first reading access but I didn't find how to fix it. I hope someone can help.
void I2C1_EV_IRQHandler(void)
{
    switch (I2C_GetLastEvent(I2C1))
    {
        case I2C_EVENT_MASTER_MODE_SELECT:          /*EV5*/
              if(tran_receiv==0)
              {
                /* Master Transmitter ----------------------------------------------*/
                /* Send slave Address for write */
                I2C_Send7bitAddress(IOE_I2C, DeviceAddr, I2C_Direction_Transmitter);
            tran_receiv=1;
              }
              else
              {
                /* Master Receiver -------------------------------------------------*/
                /* Send slave Address for read */
                I2C_Send7bitAddress(I2C1, DeviceAddr, I2C_Direction_Receiver);
                tran_receiv=0;
              }
        break;
 
        /* Master Transmitter --------------------------------------------------*/
        /* Test on I2C1 EV6 and first EV8 and clear them */
        case I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED:
            /* Send the Register Address */
            I2C_SendData(IOE_I2C, RegisterAddr);
            I2C_TransmitPEC(I2C2, ENABLE);
            break;
 
        case I2C_EVENT_MASTER_BYTE_TRANSMITTED: /* With BTF EV8-2 */
            /* I2C1 Re-START Condition */
                    I2C_GenerateSTART(I2C1, ENABLE);
                break;
 
        /* Master Receiver -------------------------------------------------------*/
//             case I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED:
//         
//         break;
         /* Test on I2C1 EV7 and clear it */
         case I2C_EVENT_MASTER_BYTE_RECEIVED:
            I2C_TransmitPEC(I2C1, ENABLE);
                   /* Disable ACK and send I2C1 STOP condition before receiving the last data */
                  if(idx == (Tx2BufferSize))
                  {
                /* Disable I2C1 acknowledgement */
                I2C_AcknowledgeConfig(I2C1, DISABLE);
                /* Send I2C1 STOP Condition */
                I2C_GenerateSTOP(I2C1, ENABLE);
            I2C_ITConfig(I2C1, I2C_IT_BUF | I2C_IT_EVT, DISABLE);  
                GPIO_ToggleBits(GPIOD, GPIO_Pin_12); 
 
                //I2C_AcknowledgeConfig(I2C1, ENABLE);
 
            }
            else
            {
                /* Store I2C1 received data */
                        I2C1_Buffer_Rx[idx++] = I2C_ReceiveData (I2C1);
            }
      default:
      break;
 
    }
}

Outcomes