ADICUP3029/AD5940 I2C issues

Dear Analog (),


I am using the AD5940_BIOZ-2Wire example with the evaluation board for AD5940 (+ADICUP3029). I am attempting to write I2C commands to an external GPIO expander, but the code gets stuck. 

Initially I set up an I2C handle inside AD5940Main.c as seen below:

  /* Setup I2C */
  /* device handle */
  ADI_I2C_HANDLE i2cDevice;
  
  //Dont use pinmux since i2c pins are already defined in adi_i2c_v1.c
  //adi_initpinmux();
  
  /* check set speed API */
  if(ADI_I2C_SUCCESS == adi_i2c_Open(0, ADI_I2C_MASTER, &devMem, ADI_I2C_MEMORY_SIZE, &i2cDevice)){
    printf("I2C Open");
  }
  if(ADI_I2C_SUCCESS == adi_i2c_SetBitRate(i2cDevice, 400)){
    printf("I2C BitRate Set");  // top-end
  }
  if(ADI_I2C_SUCCESS == adi_i2c_SetHardwareAddress(i2cDevice, 0x20)){
    printf("I2C Addr Set");
  }

This code completes, but when I just after attempt to write on I2C using: adi_i2c_Write(i2cDevice, (unsigned char*)&Regs->Output, 1); this function gets stuck in I2C_BlockingIO() in adi_i2c_v1.c on this line:

/* Pend for the semaphore */
PEND_EVENT(DATA,ADI_I2C_ERR_RTOS);

I don't know where this semaphore would've been defined earlier in the code since the only place I can find where it otherwise could've been defined is in adi_i2c_Open(), also in adi_i2c_v1.c:

#if(ADI_CFG_ENABLE_RTOS_SUPPORT == 1)
/* create a semaphore for buffer management */
CREATE_SEM(drv->pData,ADI_I2C_ERR_RTOS);
#endif

I don't have ADI_CFG_ENABLE_RTOS_SUPPORT defined in the IAR Linker. I've tried simply out-commenting the PEND_EVENT, after which the code runs, but no data is seen on SDA or SCL.

Any suggestions on solving the issue much appreciated!

Thanks,

Andreas



Edited problem title to reflect updated problem description
[edited by: andyy at 10:07 PM (GMT 0) on 6 Dec 2018]
Parents
  • I have made a bit of progress, but still having issues making it work correctly. ()

    Since the example code for the AD5940/ADICUP3029 combo does not use an adi_pinmux.c file, and for some reason instead sets up the peripherals (UART/SPI/GPIO) by setting individual bits in relevant registers explicitly in AD5940_MCUResourceInit(), and UrtCfg(), I only just realized that the same thing has to be done to enable I2C on the I2C pins. Setting this up in a pinmux file, does enable the I2C which is now active!

    #include <ADuCM3029.h>
    
    #define I2C0_SCL0_PORTP0_MUX  ((uint16_t) ((uint16_t) 1<<8))
    #define I2C0_SDA0_PORTP0_MUX  ((uint16_t) ((uint16_t) 1<<10))
    
    int32_t adi_initpinmux(void);
    
    int32_t adi_initpinmux(void) {
        /* Port Control MUX registers */
        *pREG_GPIO0_CFG = I2C0_SCL0_PORTP0_MUX | I2C0_SDA0_PORTP0_MUX;
    
        return 0;
    }

    However, this breaks the SPI and UART communication, and halts the code again! I suspect since the config data (pADI_GPIO0) for these are overwritten when I define I2C in the pinmux file. Is there an easier way to make I2C behave without writing abstract init code as that which initializes SPI/UART (in AD5940_MCUResourceInit() in ADICUP3029Port.c and UrtCfg() in main.c)?

    Thanks!

    Andreas

Reply
  • I have made a bit of progress, but still having issues making it work correctly. ()

    Since the example code for the AD5940/ADICUP3029 combo does not use an adi_pinmux.c file, and for some reason instead sets up the peripherals (UART/SPI/GPIO) by setting individual bits in relevant registers explicitly in AD5940_MCUResourceInit(), and UrtCfg(), I only just realized that the same thing has to be done to enable I2C on the I2C pins. Setting this up in a pinmux file, does enable the I2C which is now active!

    #include <ADuCM3029.h>
    
    #define I2C0_SCL0_PORTP0_MUX  ((uint16_t) ((uint16_t) 1<<8))
    #define I2C0_SDA0_PORTP0_MUX  ((uint16_t) ((uint16_t) 1<<10))
    
    int32_t adi_initpinmux(void);
    
    int32_t adi_initpinmux(void) {
        /* Port Control MUX registers */
        *pREG_GPIO0_CFG = I2C0_SCL0_PORTP0_MUX | I2C0_SDA0_PORTP0_MUX;
    
        return 0;
    }

    However, this breaks the SPI and UART communication, and halts the code again! I suspect since the config data (pADI_GPIO0) for these are overwritten when I define I2C in the pinmux file. Is there an easier way to make I2C behave without writing abstract init code as that which initializes SPI/UART (in AD5940_MCUResourceInit() in ADICUP3029Port.c and UrtCfg() in main.c)?

    Thanks!

    Andreas

Children