主题中讨论的其他器件:HALCOGEN
工具与软件:
在 Halcogen I2C 驱动程序代码中,i2cSend ()
void i2cSend(i2cBASE_t *i2c, uint32 length, uint8 * data) { uint32 index = i2c == i2cREG1 ? 0U : 1U; /* USER CODE BEGIN (17) */ /* USER CODE END */ if ((g_i2cTransfer_t[index].mode & (uint32)I2C_TX_INT) != 0U) { /* we are in interrupt mode */ /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */ g_i2cTransfer_t[index].data = data; /* start transmit by sending first byte */ /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */ i2c->DXR = (uint32)*g_i2cTransfer_t[index].data; /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */ g_i2cTransfer_t[index].data++; /* Length -1 since one data is written already */ g_i2cTransfer_t[index].length = (length - 1U); /* Enable Transmit Interrupt */ i2c->IMR |= (uint32)I2C_TX_INT; } else { /* send the data */ /* snipped */ } /* USER CODE BEGIN (18) */ /* USER CODE END */ }
请注意:
g_i2cTransfer_t[index].length =(length - 1u);
然后、在 ISR 中:
case 5U: /* USER CODE BEGIN (42) */ /* USER CODE END */ /* transmit */ /*SAFETYMCUSW 30 S MR:12.2,12.3 <APPROVED> "Used for data count in Transmit/Receive polling and Interrupt mode" */ if (g_i2cTransfer_t[0U].length > 0U) { i2cREG1->DXR = (uint32) *g_i2cTransfer_t[0U].data; /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */ g_i2cTransfer_t[0U].data++; g_i2cTransfer_t[0U].length--; if(g_i2cTransfer_t[0U].length == 0U) { /* Disable TX interrupt after desired data count transfered*/ i2cREG1->IMR &= (uint32)(~(uint32)I2C_TX_INT); i2cNotification(i2cREG1, (uint32)I2C_TX_INT); } } break;
请注意:
如果(g_i2cTransfer_t[0U].length > 0u)
因此,如果您发送1个字节,当 Tx 完成中断触发时,将不会调用 i2cNotification ()。
这没有太大帮助。