主题中讨论的其他器件:TCA9535
工具/软件:TI-RTOS
您好!
在 BIOS 开始之前、我正在使用 I2C0主器件访问从器件 TCA9535。 这在调试模式下运行良好、但在释放模式下不运行。
使用的工作台:IAR Embedded Workbench IDE
下面是我的代码片段。
空 init()
{
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOB);
//使用前必须启用 I2C0外设。
SysCtlPeripheralEnable (SYSCTL_Periph_I2C0);
//为端口 B2和 B3上的 I2C0功能配置引脚复用。
GPIOPinConfigure (GPIO_PB2_I2C0SCL);
GPIOPinConfigure (GPIO_PB3_I2C0SDA);
GPIOPinTypeI2CSCL (GPIO_PORTB_BASE、GPIO_PIN_2);
GPIOPinTypeI2C (GPIO_PORTB_BASE、GPIO_PIN_3);
GPIOPadConfigSet (GPIO_PORTB_BASE、GPIO_PIN_3、GPIO_Strength _8mA_SC、GPIO_DIR_MODE_HW | GPIO_PIN_TYPE_OD);
//启用 I2C0主机模块
I2CMasterEnable (I2C0_BASE);
I2C_init();
}
void TCA9535_access (uint8_t *txData、uint8_t txdataLen、uint8_t *rxdata、uint8_t rxdataLen)
{
uint8_t ret = 0;
uint8_t txdataIndex = 0、rxdataIndex = 0;
I2CMasterSlaveAddrSet (I2C0_BASE、TCA9535_address、false);
while (I2CMasterBusy (I2C0_BASE)){}
if (txdataLen!= 0)
{
if (txdataLen = 1)
{
I2CMasterDataPut (I2C0_BASE、txData[txdataIndex]);
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_SEND);
while (I2CMasterBusy (I2C0_BASE)){}
}
其他
{
I2CMasterDataPut (I2C0_BASE、txData[txdataIndex]);
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C0_BASE)){}
for (txdataIndex = 1;txdataIndex <(txdataLen - 1);txdataIndex++)
{
I2CMasterDataPut (I2C0_BASE、txData[txdataIndex]);
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C0_BASE)){}
}
I2CMasterDataPut (I2C0_BASE、txData[txdataIndex]);
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_FINISH);
while (I2CMasterBusy (I2C0_BASE)){}
}
}
if (rxdataLen!= 0)
{
I2CMasterSlaveAddrSet (I2C0_BASE、TCA9535_address、TRUE);
while (I2CMasterBusy (I2C0_BASE)){}
if (rxdataLen = 1)
{
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_Receive);
while (I2CMasterBusy (I2C0_BASE)){}
RET = I2CMasterDataGet (I2C0_BASE)& 0xFF;
rxdata[rxdataIndex]= ret;
}
其他
{
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_Receive_start);
while (I2CMasterBusy (I2C0_BASE)){}
RET = I2CMasterDataGet (I2C0_BASE)& 0xFF;
rxdata[rxdataIndex]= ret;
for (rxdataIndex = 1;rxdataIndex <(rxdataLen - 1);rxdataIndex++)
{
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_Receive_CONT);
while (I2CMasterBusy (I2C0_BASE)){}
RET = I2CMasterDataGet (I2C0_BASE)& 0xFF;
rxdata[rxdataIndex]= ret;
}
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_Receive_finish);
while (I2CMasterBusy (I2C0_BASE)){}
RET = I2CMasterDataGet (I2C0_BASE)& 0xFF;
rxdata[rxdataIndex]= ret;
}
}
}
请提供您的信息。