Gerasin Ivan

i2c on kinetis

Discussion created by Gerasin Ivan on Apr 15, 2013
Latest reply on Apr 18, 2013 by pavel.krenek

Hi all!

I'm trying to use sensors with I2C-interface. To understand i2c protoloc, i started with example from CW package (using MMA7660 accelerometer). And ti works great. Next, i started to write a code for communicating with MPL115A2 (barometer) and encountered a problem with reading from sensor. I tried different variation (i really don't know what's the problem) and it returns zeros, slave address, register address.

unsigned int j,i;
  unsigned char slaveID;
  /* Send Slave address */
  slaveID = (MPL115A << 1) | 0x00; //read from MPL115
  i2c_Start();  
  i2c_write_byte(slaveID); //send address
  i2c_Wait();
   
  /* Send address of register */
  i2c_write_byte(0x04);
  i2c_Wait();
   
  /* swith to read mode */
  slaveID = (MPL115A << 1) | 0x01; //set slaveID for read
  i2c_RepeatedStart() //repeated start
  i2c_write_byte(slaveID);
  i2c_Wait();
   
   /* Put in Rx Mode */
  I2C0_C1 &= (~I2C_C1_TX_MASK);


   /* Turn off ACK */
  I2C0_C1 |= I2C_C1_TXAK_MASK;
   
  for(j = 0; j < 8; j++)
  {
  dataArray[j] = I2C0_D;
  i2c_Wait();
  }
i2c_stop();


Outcomes