AnsweredAssumed Answered

Problem with I2C.

Question asked by Evgeny Erenburg on Dec 20, 2018
Latest reply on Dec 23, 2018 by Mark Butcher

I do write operation.

 

unsigned int I2C0_Wait(void)

{

      unsigned int timeout = 0;

     

      while((I2C0_S & I2C_S_IICIF_MASK)==0)

      {

          timeout++;

          if(timeout > I2C_TIMEOUT)

            return I2C_ERROR;

      }

      I2C0_S |= I2C_S_IICIF_MASK;

      

      return 0;

}

 

void MAX7300_Write(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data)

{

    uint8_t slave_address = (slave_addr<<1) & 0xFE;

   

    //START

    I2C0_C1 |= I2C_C1_MST_MASK;

    I2C0_C1 |= I2C_C1_TX_MASK;

 

    I2C0_D = slave_address;

    I2C0_Wait();

   

    I2C0_D = reg_addr;

    I2C0_Wait();

 

    I2C0_D = *data;

    I2C0_Wait();

 

    //STOP

    I2C0_C1 &= ~I2C_C1_MST_MASK;

    I2C0_C1 &= ~I2C_C1_TX_MASK

 

    while (I2C0_S & I2C_S_BUSY_MASK) ;

}

After stop the busy flag is not cleared – I stay in while (I2C0_S & I2C_S_BUSY_MASK).

 

In data sheet it says

BUSY

Indicates the status of the bus regardless of slave or master mode. This bit is set when a START signal is
detected and cleared when a STOP signal is detected.

Outcomes