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.

[参考译文] TMS570LC4357:Halcogen:I2C 发送 ISR 代码错误

Guru**** 2348500 points
Other Parts Discussed in Thread: HALCOGEN
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1372229/tms570lc4357-halcogen-i2c-send-isr-code-wrong

器件型号:TMS570LC4357
主题中讨论的其他器件: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 ()。

这没有太大帮助。