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.
我很困惑...
I2cStateMachine.slaveAddress = MCP23017_BUS_ADDRESS_AZ;
I2cStateMachine.registerAddress = MCP23017_GPIOA_DIR_REG;
memset (&I2cStateMachine.dataBytes、0、2);
I2cStateMachine.dataSize = 2;
IntTrigger (INT_I2C0);
while (I2cStateMachine.currentState!= I2C_State_stop);
I2cStateMachine.currentState = I2C_State_Idle;
int i = 0;
while (i < 1000000){i++;}
当我运行以下代码时、我总共得到了由 I2C 主器件生成的五个中断。 第一个是0x00、我假设它是用于启动事务的 IntTrigger (INT_I2C0)调用的结果。 我将发送两个字节。 第一个字节是远程器件的寄存器地址、第二个字节是要写入该寄存器的数据。 我的中断处理程序再被调用四次、所有调用都使用中断位0x0001
#define I2C_MASTER_INT_DATA 0x00000001 //数据中断 <= 来自 driverlib 中的 I2c.h 文件。
我只需要两个中断、每个字节完成时一个中断。 我缺少什么??
清除中断是我在 ISR 中首先执行的操作。
void I2C0IntHandler (void){
uint32_t ui32I2CMasterInterruptStatus;
//获取屏蔽的中断状态并清除标志
ui32I2CMasterInterruptStatus = I2CMasterIntStatusEx (I2C0_BASE、TRUE);
I2CMasterIntClearEx (I2C0_BASE、ui32I2CMasterInterruptStatus);
switch (I2cStateMachine.currentState){
情况 I2C_State_Idle:
//发送地址字节
I2CMasterSlaveAddrSet (I2C0_BASE、I2cStateMachine.slaveAddress、I2C_OP_WRITE);
I2CMasterDataPut (I2C0_BASE、I2cStateMachine.registerAddress);
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_START);
I2cStateMachine.currentState = I2C_State_data;
字节计数= 0;
中断;
案例 I2C_State_data:
if (ui32I2CMasterInterruptStatus & I2C_MASTER_INT_NACK){
I2cStateMachine.currentState = I2C_State_stop;
}否则{
I2CMasterDataPut (I2C0_BASE、(uint8_t)(I2cStateMachine.dataBytes[byteCount]);
字节计数++;
if (byteCount < I2cStateMachine.dataSize){
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_CONT);
I2cStateMachine.currentState = I2C_State_data;
}否则{
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_FINISH);
I2cStateMachine.currentState = I2C_State_stop;
}
}
中断;
}
}
查尔斯 -
我能够使它正常工作。 我不确定这是最好的方法、但这里是...
这三行被添加到中断处理程序中、这样、当中断发生且总线空闲时、我只转换到状态机的下一状态。
有什么想法?
uint32_t MRiS_R = I2C0_MRiS_R;
I2CMasterIntClear (I2C0_BASE);
if ((I2C0_MCS-78_R & 0x00000020)&&(MRI_R & 0x00000001)){return;}
您好 Brian、
我相信您在另一篇文章中看到了以下内容:
I2CMasterIntEnableEx (I2C0_BASE、(I2C_MASTER_INT_ARB_Lost | I2C_MASTER_INT_STOP | I2C_MASTER_INT_NACK |
I2C_MASTER_INT_TIMEOUT | I2C_MASTER_INT_DATA);
您可以尝试以下操作:
I2CMasterIntEnableEx (I2C0_BASE、(I2C_MASTER_INT_TIMEOUT | I2C_MASTER_INT_DATA);
原因是您将为 TM4C129创建的示例代码移植到 TM4C123。 TM4C123只有两个中断源。 请参阅下面的内容。 我只是想确保额外的中断不是由一些幻象事件引起的。