4809 views|4 replies

6555

Posts

0

Resources
The OP
 

AWR1642: Add I2C driver support to the existing mmWave SDK demo [Copy link]

In some special occasions, it is necessary to use AWR1642 to adjust the output voltage of PMIC or read the internal working status of PMIC. In this case, I2C interface is needed to read and write PMIC. This article introduces the steps and operations required to integrate I2C interface driver into the existing mmWave SDK demo. The test environment of this article is as follows: Test software version: mmWave SDK 2.0.0.4
  • Test hardware: AWR1642BOOST EVM 1. Add I2C driver code to mmWave SDK demo The first step is to add code to include and initialize the I2C driver. This driver is required to support both sending and receiving from the I2C interface. The following is the C code added in mss_main.c to initialize the I2C driver. This test code can be copied to an existing project. The I2C driver operation steps are: GPIO initialization, I2C driver initialization, and I2C configuration to rewrite the PMIC (LP87524B) register to achieve PMIC output voltage regulation. Note that the LP87524B register information comes from its datasheet: LP87524B/J-Q1 4-A + 2.5-A + Two 1.5-A Buck Regulators with Integrated Switches Data Sheet (Rev. A) , the I2C driver reference code is as follows: 85)]#include
    static int32_t I2C_GPIOInit(void)
    {
    #if (defined(SOC_XWR14XX))
       /* Setup the PINMUX to bring out the XWR14xx I2C pins */
       Pinmux_Set_OverrideCtrl(SOC_XWR14XX_PINR3_PADAH, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
       Pinmux_Set_FuncSel(SOC_XWR14XX_PINR3_PADAH, SOC_XWR14XX_PINR3_PADAH_I2C_SDA);
       Pinmux_Set_OverrideCtrl(SOC_XWR14XX_PINP4_PADAI, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
       Pinmux_Set_FuncSel(SOC_XWR14XX_PINP4_PADAI, SOC_XWR14XX_PINP4_PADAI_I2C_SCL);
    #else
       /* Setup the PINMUX to bring out the XWR16xx I2C pins */
       Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINF13_PADAH, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
       Pinmux_Set_FuncSel(SOC_XWR16XX_PINF13_PADAH, SOC_XWR16XX_PINF13_PADAH_I2C_SDA);

       Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PING14_PADAI, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
       Pinmux_Set_FuncSel(SOC_XWR16XX_PING14_PADAI, SOC_XWR16XX_PING14_PADAI_I2C_SCL);
    #endif
       return 0;
    }
    static int32_t I2C_Communication_Test()
    {
       bool           retVal = false;
       int32_t         errCode = 0;
       uint32_t       arg;
       uint8_t                 rxData[16];
       uint8_t                 txData[16];
       I2C_Transaction         i2cTransaction;
       I2C_Handle     i2cHandle;
       I2C_Params     i2cParams;

       /* Reset the transmit and receive buffer */
       memset(&rxData, 0, sizeof (rxData));

       /* Initializa the I2C driver */
       I2C_init();

       /* Initialize the I2C driver default parameters */
       I2C_Params_init(&i2cParams);

       i2cParams.transferMode = I2C_MODE_BLOCKING;
       i2cParams.bitRate = I2C_100kHz;

       /* Open the I2C driver */
       i2cHandle = I2C_open(0, &i2cParams);

       if (i2cHandle == NULL)
       {
           System_printf ("Error: I2C Driver Open failed\n");
           return -1;
       }

       /* Configure the I2C device in I2C_CMD_ADDR_MODE mode */
       arg = 0;//arg set to 0, and the I2C addr mode is 7-bit.
       errCode = I2C_control (i2cHandle, I2C_CMD_ADDR_MODE,(void* )&arg);
       if (errCode < 0)
       {
           System_printf ("Error: I2C control Set I2C_CMD_ADDR_MODE failed [Error code %d]\n", errCode);
           return -1;
       }

    //read the LP87524B buck3 output voltage register
       txData[0] = 0x10;
       i2cTransaction.slaveAddress = 0x60;//LP87524B/J-Q1 Device Address = 0x60
       i2cTransaction.writeBuf = txData;
       i2cTransaction.writeCount = 1;
       i2cTransaction.readBuf = rxData;
       i2cTransaction.readCount = 1;
       retVal = I2C_transfer(i2cHandle, &i2cTransaction);
       if (retVal == false)
       {
           System_printf ("Error: I2C Transfer failed\n");
           return -1;
       }
       System_printf("I2C_READ: addr=0x%x, Val=0x%x\n",txData[0],rxData[0]);
    //write the LP87524B buck3 output voltage = 2.0V
       txData[0] = 0x10;
       txData[1] = 0xbb;//default=0xca,2.3V,0xb1=1.8V, 0xbb=2.0V
       i2cTransaction.slaveAddress = 0x60;//LP87524B/J-Q1 Device Address = 0x60
       i2cTransaction.writeBuf = txData;
       i2cTransaction.writeCount = 2;
       i2cTransaction.readBuf = rxData;
       i2cTransaction.readCount = 0;
       retVal = I2C_transfer(i2cHandle, &i2cTransaction);
       if (retVal == false)
       {
           System_printf ("Error: I2C Transfer failed\n");
           return -1;
       }
       System_printf("I2C_Write: LP87524B buck3 = 2.0V Done\n");

    //read the LP87524B buck3 output voltage register
       txData[0] = 0x10;
       i2cTransaction.slaveAddress = 0x60;//LP87524B/J-Q1 Device Address = 0x60
       i2cTransaction.writeBuf = txData;
       i2cTransaction.writeCount = 1;
       i2cTransaction.readBuf = rxData;
       i2cTransaction.readCount = 1;
       retVal = I2C_transfer(i2cHandle, &i2cTransaction);
       if (retVal == false)
       {
           System_printf ("Error: I2C Transfer failed\n");
           return -1;
       }
       System_printf("I2C_READ: addr=0x%x, Val=0x%x\r\n",txData[0],rxData[0]);

    //write the LP87524B buck2 output voltage = 1.5V
       txData[0] = 0x0e;
       txData[1] = 0Xa2;//default=0xb1,1.8V, 0x4d=1V 0xa2=1.5V
       i2cTransaction.slaveAddress = 0x60;//LP87524B/J-Q1 Device Address = 0x60
       i2cTransaction.writeBuf = txData;
       i2cTransaction.writeCount = 2;
       i2cTransaction.readBuf = rxData;
       i2cTransaction.readCount = 0;
       retVal = I2C_transfer(i2cHandle, &i2cTransaction);
       if (retVal == false)
       {
           System_printf ("Error: I2C Transfer failed\n");
           return -1;
       }
       System_printf("I2C_Write: LP87524B buck2 = 1.5V Done\n");
       if (retVal == false)
       {
           System_printf ("Error: I2C combined Transfer to Slave failed\n");
           return -1;
       }
       /* Close I2C driver */
       I2C_close(i2cHandle);
       return 0;
    }

    //Call these function in void MmwDemo_mssInitTask(UArg arg0, UArg arg1)
       errCode = I2C_GPIOInit();
                    if (errCode == -1)
           System_printf("I2C_GPIOInit Error\r\n");
       errCode = I2C_Communication_Test();
       if (errCode == -1)
           System_printf("I2C_Communication_Test Error\n");
       else
           System_printf("I2C_Communication_Test Done\n");
    2.      将工程链接到I2C驱动库
    最后一步是通过链接I2C驱动程序来构建可执行文件。 如果使用CCS项目,可以将I2C驱动程序添加到项目的链接器属性中,如图1所示。
    图1. CCS Project Linker Properties

    如果使用makefile编译工程,执行相同的程序。
    ###################################################################################
    # Additional libraries which are required to build the DEMO:
    ###################################################################################
    MSS_MMW_DEMO_STD_LIBS = $(R4F_COMMON_STD_LIB)                                                              \
                                            -llibpinmux_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                           \
                                            -llibdma_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                                                \
                                            -llibcrc_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                                  \
                                            -llibuart_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                                                \
                                            -llibgpio_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                               \
                                            -llibmailbox_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                          \
                                            -llibmmwavelink_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                  \
                                            -llibmmwave_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                       \
                                            -llibcli_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)                                  \
                                            -llibi2c_$(MMWAVE_SDK_DEVICE_TYPE).$(R4F_LIB_EXT)
    MSS_MMW_DEMO_LOC_LIBS = $(R4F_COMMON_LOC_LIB)                                                              \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/drivers/pinmux/lib                              \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/drivers/uart/lib                                    \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/drivers/dma/lib                                   \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/drivers/crc/lib                                      \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/drivers/gpio/lib                                   \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/drivers/mailbox/lib                             \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/control/mmwavelink/lib                     \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/control/mmwave/lib                           \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/utils/cli/lib                                          \
                                       -i$(MMWAVE_SDK_INSTALL_PATH)/ti/utils/i2c/lib

    3.      运行测试例程
    运行测试程序后,CCS控制台输出打印信息如下,使用万用表测量LP87524输出电压即为设置的电压,I2C驱动添加成功。
    **********************************************
    Debug: Launching the Millimeter Wave Demo
    **********************************************
    I2C_READ: addr=0x10, Val=0xca
    I2C_Write: LP87524B buck3 = 2.0V Done
    I2C_READ: addr=0x10, Val=0xbb
    I2C_Write: LP87524B buck2 = 1.5V Done
    I2C_Communication_Test Done
    4.      参考资料

  • This post is from Microcontroller MCU

    Latest reply

    Useful, saved   Details Published on 2020-3-31 11:05
     

    172

    Posts

    0

    Resources
    2
     
    Thanks for sharing!
    This post is from Microcontroller MCU
     
     

    2618

    Posts

    0

    Resources
    3
     
    Really nice to share, thank you.
    This post is from Microcontroller MCU
     
     
     

    935

    Posts

    1

    Resources
    4
     
    This post is from Microcontroller MCU
     
    Personal signature存储芯片/MCU/SRAM/PSRAM/DDR/FLASH/MRAM。web.www.sramsun.com  QQ3161422826 TEL:13751192923
     
     

    1

    Posts

    0

    Resources
    5
     

    Useful, saved

    This post is from Microcontroller MCU
     
     
     

    Guess Your Favourite
    Find a datasheet?

    EEWorld Datasheet Technical Support

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list