What are the proper steps to initialize and use I2C using the InternalI2C component?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What are the proper steps to initialize and use I2C using the InternalI2C component?

688 Views
tomii
Contributor III

I've been having no luck getting I2C to work with my FRDM-KE02Z board..  I'm using the KDS 1.0.1 IDE and attempting to use the built-in component library, but I am obviously doing something wrong.  I've enabled the devices and chose the appropriate slave, but every time I try to read/write data, I get an error (ERR_DISABLED)...  It would seem that maybe I'm not correctly enabling turning the I2C hardware.  a code snippet is below, "Accelerometer" is an "InternalI2C" component.

 

 

  Accelerometer_Init();

  error = Accelerometer_Enable();            //    enable the accelerometer

  printf("Err:%3d \r\n", error);

 

  error = Accelerometer_SelectSlave(0x1D);    //    accelerometer address is 0x1D

  printf("Err:%3d \r\n", error);

 

  error = Accelerometer_SendChar(0x40);        //    reset the accelerometer

  printf("Err:%3d \r\n", error);

 

//  while( 1 )

//  {

      error = Accelerometer_SendChar(0x00);                    //    Send start address

      printf("Err:%3d \r\n", error);

 

      error = Accelerometer_RecvBlock(AData, 7, &bytes);    //    read back 7 bytes

      printf("Err:%3d \r\n", error);

 

      error = Accelerometer_RecvChar(&bytes);

      printf("Err:%3d \r\n", error);

 

      status = AData[0];

//      xG = (AData[1]<<8) + AData[2];

//      yG = (AData[3]<<8) + AData[4];

//      zG = (AData[5]<<8) + AData[6];

      xG = AData[1];

      yG = AData[3];

      zG = AData[5];

 

      printf("Err:%3d BytesRX:%3d Status:%3d X:%6d Y:%6d Z:%6d\r\n", error, bytes, status, xG, yG, zG);

Labels (1)
Tags (4)
0 Kudos
0 Replies