在一些特殊的使用場合,有需要使用AWR1642對PMIC的輸出電壓進行調(diào)節(jié),或是讀取PMIC 內(nèi)部的工作狀態(tài),此時需要I2C接口對PMIC進行讀寫操作,本文介紹了在現(xiàn)有的mmWave SDK demo中集成I2C接口驅(qū)動所需的步驟及操作。
本文的測試環(huán)境如下:
測試軟件版本:mmWave SDK 2.0.0.4
測試硬件:AWR1642BOOST EVM
1. 在mmWave SDK demo中增加I2C驅(qū)動代碼
第一步是添加代碼以包含和初始化I2C驅(qū)動程序。從I2C接口發(fā)送和接收均需要此驅(qū)動程序的支持,以下是在mss_main.c中添加的初始化I2C驅(qū)動程序的C代碼。此測試代碼可以復(fù)制到現(xiàn)有工程中。I2C驅(qū)動操作步驟為:GPIO初始化,I2C驅(qū)動初始化,配置I2C改寫PMIC(LP87524B)寄存器以實現(xiàn)PMIC輸出電壓調(diào)節(jié)。
注意LP87524B寄存器信息來源于其datasheet:LP87524B/J-Q1具有集成開關(guān)的具有集成開關(guān)的 4-A + 2.5-A + 兩個 1.5-A 降壓穩(wěn)壓器 數(shù)據(jù)表 (Rev. A),I2C驅(qū)動參考代碼如下:
#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 failedn");
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 failedn");
return -1;
}
System_printf("I2C_READ: addr=0x%x, Val=0x%xn",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 failedn");
return -1;
}
System_printf("I2C_Write: LP87524B buck3 = 2.0V Donen");
//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 failedn");
return -1;
}
System_printf("I2C_READ: addr=0x%x, Val=0x%xrn",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 failedn");
return -1;
}
System_printf("I2C_Write: LP87524B buck2 = 1.5V Donen");
if (retVal == false)
{
System_printf ("Error: I2C combined Transfer to Slave failedn");
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 Errorrn");
errCode = I2C_Communication_Test();
if (errCode == -1)
System_printf("I2C_Communication_Test Errorn");
else
System_printf("I2C_Communication_Test Donen");
2. 將工程鏈接到I2C驅(qū)動庫
最后一步是通過鏈接I2C驅(qū)動程序來構(gòu)建可執(zhí)行文件。 如果使用CCS項目,可以將I2C驅(qū)動程序添加到項目的鏈接器屬性中,如圖1所示。
圖1. CCS Project Linker Properties
如果使用makefile編譯工程,執(zhí)行相同的程序。
###################################################################################
# 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. 運行測試?yán)?/strong>
運行測試程序后,CCS控制臺輸出打印信息如下,使用萬用表測量LP87524輸出電壓即為設(shè)置的電壓,I2C驅(qū)動添加成功。
**********************************************
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
審核編輯:郭婷
-
PMIC
+關(guān)注
關(guān)注
15文章
334瀏覽量
109473 -
I2C
+關(guān)注
關(guān)注
28文章
1486瀏覽量
123627 -
GPIO
+關(guān)注
關(guān)注
16文章
1204瀏覽量
52057
發(fā)布評論請先 登錄
相關(guān)推薦
評論