工具与软件:
您好!
我将使用 CC2340R5、SDK 版本7.40、basic_ble 工程。
我将通过 I2C 与微控制器进行 BLE 连接。
初级侧控制器将是主器件、而 BLE 将是从器件。
我的查询是:i)如何在给定的 SDK 7.40中将 I2C 配置为从设备?
ii)此外、是否有相同的示例代码?
我看不到任何这样可以在从模式下配置 I2C 的 API。
此致、
Rushikesh。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
您好!
我将使用 CC2340R5、SDK 版本7.40、basic_ble 工程。
我将通过 I2C 与微控制器进行 BLE 连接。
初级侧控制器将是主器件、而 BLE 将是从器件。
我的查询是:i)如何在给定的 SDK 7.40中将 I2C 配置为从设备?
ii)此外、是否有相同的示例代码?
我看不到任何这样可以在从模式下配置 I2C 的 API。
此致、
Rushikesh。
Rushikesh 您好!
为了在 CC2340R5中将 I2C 配置为从器件、您需要覆盖 在 I2CCC23XX_initHw ()中完成的 I2C 配置、即禁用主器件并启用从器件。 本文档中的主器件称为控制器、从器件称为目标。 请参阅 source\ti\devices\cc23x0r5\driverlib\SDK 中 i2c.h 有关如何禁用 i2c 控制器和启用 i2c 目标的文档。
我们没有此操作的任何示例代码。
此致、
David Chen
尊敬的 David:
这是我的以下代码、用于测试。
回调有时不会触发、也不会 调用 I2C_SEND_RECEIVE_DATA()函数。
void I2C_Init(void)
{
uint32_t status = 0;
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(CONFIG_I2C_0, &i2cParams);
if (i2c == NULL)
{
//Display_printf(display, 0, 0, "Error Initializing I2C\n");
while (1) {}
}
else
{
// Display_printf(display, 0, 0, "I2C Initialized!\n");
}
/*Disabling master mode*/
I2CControllerDisable(I2C0_BASE);
/*Enable slave mode*/
I2CTargetEnable(I2C0_BASE);
I2CTargetInit(I2C0_BASE, 0xAA);
IntRegister(INT_I2C0_IRQ, i2c_callback);
IntEnable(INT_I2C0_IRQ);
I2CTargetEnableInt(I2C0_BASE, (I2C_TARGET_INT_STOP | I2C_TARGET_INT_START | I2C_TARGET_INT_DATA));
//I2C_close(i2c);
}
void i2c_callback(void)
{
BLEAppUtil_invokeFunctionNoData(I2C_send_receive_data);
}
void I2C_send_receive_data()
{
uint8_t status = 0;
uint8_t txbuffer = 10;
status = I2CTargetStatus(I2C0_BASE);
if(I2C_TARGET_ACT_RREQ_FBR == status)
{
RxBuffer[0] = I2CTargetGetData(I2C0_BASE);
I2CTargetPutData(I2C0_BASE, txbuffer);
}
else if(I2C_TARGET_ACT_RREQ == status)
{
RxBuffer[0] = I2CTargetGetData(I2C0_BASE);
RxBuffer[0] = I2CTargetGetData(I2C0_BASE);
I2CTargetPutData(I2C0_BASE, txbuffer);
}
else if(I2C_TARGET_ACT_TREQ == status)
{
RxBuffer[0] = I2CTargetGetData(I2C0_BASE);
RxBuffer[0] = I2CTargetGetData(I2C0_BASE);
I2CTargetPutData(I2C0_BASE, txbuffer);
}
else
{
//Error
}
}
您能仔细看一下代码来帮我找出问题吗?
此致、
Rushikesh。
Rushikesh 您好!
您能否提供有关测试代码何时工作以及何时不工作的逻辑分析仪或调试器/寄存器屏幕的任何屏幕截图?
我可以就您的测试代码提供一些一般反馈。
您是否在创建自己的 I2C_Init()函数、因为我看不到在何处启用 I2C 驱动程序?
关于代码本身:
在第19行、当您禁用主模式时、您需要先使用 I2CControllerDisableInt (I2C0_BASE)禁用主中断。
在第22行,我认为您不需要此函数,因为 I2CTargetInit()也会启用目标模块。
在第26行、我建议 在调用 I2CTargetEnableInt()之前添加 I2CTargetClearInt() 。
我希望其中的一些内容有助于您使用测试代码。
此致、
David Chen