AnsweredAssumed Answered

Simple SDK I2C Routine

Question asked by PHIL HALE on Dec 29, 2015
Latest reply on Dec 31, 2015 by PHIL HALE

I am continuing my efforts to learn the Kinetis SDK by now evaluating the I2C routines. I have a simple project where I am trying to communicate with a Analog Devices chip at slave address 0xB0.

Here is my code:  ( I am trying to send two writes to the ADI chip. )

void I2C_WriteRegister(uint32_t instance, uint8_t addr, uint8_t reg, uint8_t data)

{

  uint8_t regBuff[1];

  uint8_t datBuff[1];

  i2c_status_t ret;

  i2c_device_t deviceInfo = {

   .address = addr,

   .baudRate_kbps = I2C_COMM_SPEED,   // 100U

  };

 

  regBuff[0] = reg;

  datBuff[0] = data;

  ret = I2C_DRV_MasterSendDataBlocking(instance, &deviceInfo, regBuff, 1, datBuff, 1, 1000u);

  if (ret != kStatus_I2C_Success)

  {

       unsigned char str[64], n;

       n = sprintf((char *)str,"\n\rI2C Write Error: 0x%02x 0x%02x 0x%02x - Ret = 0x%02x",addr, reg, data, ret);

       UART_DRV_SendDataBlocking(UART0_IDX, str, n, 1000u);

  }

  //PIT_DRV_DelayUs(50);

}

 

/*lint -save  -e970 Disable MISRA rule (6.3) checking. */

int main(void)

/*lint -restore Enable MISRA rule (6.3) checking. */

{

  /* Write your local variable definition here */

 

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

 

  /* Write your code here */

  GPIO_DRV_SetPinOutput(LED_RED);

 

  unsigned char str[] = "\n\rMy Kinetis Design Studio SDK Test Program\n\r";

  UART_DRV_SendDataBlocking(UART0_IDX, str, sizeof(str), 1000u);

 

  I2C_WriteRegister(i2cCom0_IDX, 0xB0, 0xFF, 0xFF);

  I2C_WriteRegister(i2cCom0_IDX, 0xB0, 0xE5, 0x82);

 

  GPIO_DRV_SetPinOutput(LED_BLUE);

 

  for(;;)

  {}

 

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/

  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/

  #ifdef PEX_RTOS_START

    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */

  #endif

  /*** End of RTOS startup code.  ***/

  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

  for(;;){}

  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

 

 

/* END main */

 

I believe I am getting a Nak back from the ADI chip. See below.

ScreenHunter_117 Dec. 29 17.58.jpg

Any idea why this code is failing?

 

I know the hardware works fine because I have another application in Keil that works with this hardware.

 

Thank you.

 

Phil

Original Attachment has been moved to: ProjectInfo.zip

Outcomes