AnsweredAssumed Answered

ADUC7061 I2C Slave

Question asked by vnn on Dec 9, 2014
Latest reply on Dec 10, 2014 by vnn

Hello,

i had a Problem when i tried to driver I2C Slave on ADUC7061. I have a

EVAL Board and mIDAS-Link.

Master sends request every 150ms  to read 5 Bytes from slave. In scope i saw no Action of slave

just have seen NACK by tranfers address. With debugger i saw the value of I2CSSTA Register is 0x0421.

Best regards

Ngoc

 

P/S: here is the code (IAR EVARM)

void i2c_slaves_init(void)
{
  uint8_t i = 0;
  // Configure P0.1 and P0.3 for I2C mode
GP0CON0 |= BIT4 + BIT12; // Select SPI/I2C alternative function for P0.1 & P0.3
GP0KEY1 = 0x7;     // Write to GP0KEY1
GP0CON1 |= BIT1;     // Select I2C functionality for P0.1 & P0.3
GP0KEY2 = 0x13;     // Write to GP0KEY2
 
  I2CID0 = 0x20; // Configure Slave's I2C network address

  I2CFSTA = BIT8;   // Flush Slave Tx FIFO
  I2CFSTA &= ~BIT8;
  // Enable I2C Slave
  // Enable I2C Stop condition detected interrupt
  // Enable I2C Receive interrupt
  // Enable I2C Transmit interrupt
  I2CSCON = BIT0 + BIT8 + BIT9 + BIT10;
  I2C_Status = I2C_STATUS_DEFAULT; 
  I2C_Rx_index = 0;
  I2C_Tx_index = 0;
  for(i = 0; i < I2C_BUFFER_SIZE; i++)
  {
    I2C_Tx_Buf[i] = 0;
    I2C_Rx_Buf[i] = 0;
  }
  I2C_timeout_tick = 0;
  IRQEN |= BIT16;    // Enable I2C Slave IRQ interrupts  
}

 

and ISR

__irq void IRQ_Handler(void)

{

  volatile uint32_t IRQSTATUS = 0;

volatile uint16_t I2CSSTATUS = 0;

  if((IRQSTATUS & BIT16) == BIT16)

  {

    I2CSSTATUS = I2CSSTA;  

    // I2C Slave receiver handler

    if((I2CSSTATUS & BIT3) == BIT3)

    {

      if(I2C_Status != I2C_STATUS_RX_COMP)

      {

        if(I2C_Rx_index < I2C_BUFFER_SIZE)

        {

          I2C_Rx_Buf[I2C_Rx_index++] = I2CSRX;

        }

        if(I2C_Rx_index == I2C_BUFFER_SIZE)

        {

          I2C_Status = I2C_STATUS_RX_COMP;

        }

      }

    }

    // I2C Slave transmit handler

    if((I2CSSTATUS & BIT2) == BIT2)

    {

      if(I2C_Status != I2C_STATUS_TX_COMP)

      {

        I2CSTX = I2C_Tx_Buf[I2C_Tx_index++];

      }

      if(I2C_Tx_index == I2C_BUFFER_SIZE)

      {

        I2C_Status = I2C_STATUS_TX_COMP;

      }

    }

    // I2C Slave received re start condition

    if((I2CSSTATUS & BIT13) == BIT13)

    {

      I2C_Rx_index = 0;

      I2C_Tx_index = 0;

    }

    if((I2CSSTATUS & BIT10) == BIT10)

    {

      I2C_Rx_index = 0;

      I2C_Tx_index = 0;

      I2CFSTA = BIT8;   // Flush Slave Tx FIFO

      I2CFSTA &= ~BIT8;

    }

  }

}

Outcomes