您好,
我有一 个非常简单的 Matlab 2020b Simulink,带有一个 SystemObject 块。 此块只调用一些执行某些 I2C 事务的手代码。 当我在28069启动板上运行时,我的手代码按预期工作。 但是,当我在28069定制板上使用 Simulink Code Generation 运行相同的 I2C 代码时,该代码将无法按预期工作。
问题是,当调用我的 I2C ISR 时,I2C 中断源总是返回0。 我预期源为 I2C_ARDY _ISRC 或 I2C_nack_ISRC。
}
Uint8 i2cdrvCmdCheckSlavePresent(
Uint8 slaveAddr,
Uint32 timeoutMs)
{
Uint8 isSuccess = !i2cdrvIsBusy();
if (isSuccess)
{
m_state = I2CDRVSTATE_BUSY;
...
I2caRegs.I2CSAR = slaveAddr;
// Enable ARDY and NACK interrupts
I2caRegs.I2CIER.all = 0x0006;
// Mode -> FREE, STT, MST, TRX, RM, IRS all set.
I2caRegs.I2CMDR.all = 0x66A0;
}
return isSuccess;
}
static void _init(void)
{
// Put in reset
I2caRegs.I2CMDR.all = 0x0000;
// Add our interrupt handler to vector table
EALLOW;
PieVectTable.I2CINT1A = &_i2cInt1AISR;
EDIS;
// Enable I2C interrupts in the PIE: Group 8 interrupt 1 and 2
PieCtrlRegs.PIEIER8.bit.INTx1 = 1;
//PieCtrlRegs.PIEIER8.bit.INTx2 = 1;
// Enable CPU INT8 which is connected to PIE group 8
IER |= M_INT8;
// Set our own address
I2caRegs.I2COAR = 0x0001;
// Clocks
I2caRegs.I2CPSC.all = CLK_PRESCALE;
I2caRegs.I2CCLKL = CLK_LOW;
I2caRegs.I2CCLKH = CLK_HIGH;
// Disable all ints
I2caRegs.I2CIER.all = 0x0000;
// Take out of reset
I2caRegs.I2CMDR.bit.IRS = 1;
}
// I2C-1A Interrupt - handles the basic I2C
static interrupt void _i2cInt1AISR(void)
{
// Read interrupt source
Uint16 intSrc = I2caRegs.I2CISRC.all; //this is always returning 0. it should return I2C_NACK_ISRC or I2C_ARDY_ISRC
switch(intSrc)
{ .... }
}
我认为 I2caRegs.I2CISRC 没有更新,因为到 ISR 被称为 I2C 模块时,它处于重置模式。 使用调试 器,我发现在 i2cdrvCmdCheckSlavePresent()函数的末尾,重置模式已关闭,中断已启用。

当我进入 i2cInt1AISR()时 ,我看到 I2C 模块处于重置状态。 当我在启动板上运行此 I2C 手代码时, I2caRegs.I2CMDR.Bit.IRS 始终为1。

进入重置模式的 I2C 模块能否成为中断源始终返回0的原因? 或者,我的 init 函数中的模块时钟频率或 SDCLK 周期是否可能是导致这种情况的原因?
我在 I2caRegs.I2CMDR.Bit.IRS 上设置了一个读取监视点,因此请查看该寄存器的写入内容。 只有_init()函数应该写入 I2CMDR。 由于附加监视点的原因,ISR 始终正确显示中断源为 nack 或 ARDY。

