AnsweredAssumed Answered

(mc13224V) I2C troubles, App hangs when trying to send data (gI2cErrModuleBusy_c error)

Question asked by Antonio Liñan Colina on Aug 6, 2012
Latest reply on Aug 6, 2012 by Antonio Liñan Colina

Hello,

 

I'm having trouble trying to write to a sensor register using the mc13224V, the configuration of the i2c module *seems* to be fine, but when trying to write the application hangs, I have read similar threads in the forum and have not find an answer, I must say I'm just beggining working with the mc13224V, and I tested the sensor communication using the open libmc1322x and it worked, so the sensor wiring, pull-up resistors, etc have been tested using the same development board.

 

The sensor's 7-bit slave address is 0x39, the operation I'm using for testing is powering the sensor by writting 0x03 to the register at 0x00, maybe I'm misunderstanding the I2c_SendData instruction and sintaxis.

 

The logic analyzer doesn't show anything (not even the clock source), the error message I receive from the sendData instruction is gI2cErrModuleBusy_c, but that's strange because between the configuration stage and the actual sendData attempt I'm waiting 1-2 seconds.

 

Am I missing a magic enable or something?

 

Below is my test code, I appreciate any hints or pointers.

 

Cheers,

 

--Antonio

 

/*********************** CONFIGURE ************************************************/

 

void foo init_sensor(){
  I2cErr_t error;

 

  /* Creates structures */
  I2cConfig_t i2cConfig;

  /* Clear and initialize */
  I2c_Init();

  /* Configure pins for I2C (functional mode 1) */
  Gpio_SetPinFunction(gGpioPin12_c, gGpioAlternate1Mode_c);
  Gpio_SetPinFunction(gGpioPin13_c, gGpioAlternate1Mode_c);

 

  /* Enables the I2C module */
  error = I2c_Enable();
  if(error != gI2cErrNoError_c){
    error_led();

    return;
  }
   
  /* Assign the interrupt handle */
  IntAssignHandler(gI2cInt_c, (IntHandlerFunc_t)&I2c_Isr);
  ITC_SetPriority(gI2cInt_c, gItcNormalPriority_c);
  ITC_EnableInterrupt(gI2cInt_c); 

  /* I2C configuration */ 
  i2cConfig.slaveAddress = 0x01; // Our slave address, not used in Master mode
  i2cConfig.freqDivider = 0x20;  // X/160, 150KHz for 24Mhz peripheral clock
  i2cConfig.saplingRate = 0x10; // Digital filter sample rate (default)
  i2cConfig.i2cInterruptEn = TRUE;
  i2cConfig.i2cBroadcastEn = FALSE;  
  error = I2c_SetConfig(&i2cConfig);

 

  if(error != gI2cErrNoError_c){
    error_led();
    return;
  }

  /* Set callback functions */
  error = I2c_SetCallbackFunction(&SensorCallback);

  if(error != gI2cErrNoError_c){
    error_led();
    return;
  }
  
  return;
}

 

/*********************** TEST COMMAND  ************************************************/

 

void foo_test(){
  I2cErr_t error;

  uint8_t cmd_buffer[] = {0x00,0x03};
  error = I2c_SendData(0x39, &cmd_buffer[0], 2, gI2cMstrReleaseBus_c);
  if(error != gI2cErrNoError_c){

    error_led();

    return;

  }

 

void SensorCallback(uint16_t transfBytesNo, uint16_t status){
  test_led_on();
}

Outcomes