请问STM8单片机CAN通信函数为什么要反复保存PSR寄存器

2019-12-10 18:23发布


为什么做can通信的函数中都有can_page的读取和最后的写入操作,不可以直接用PSR寄存器控制页面吗?
void CAN_ITConfig(CAN_IT_TypeDef CAN_IT, FunctionalState NewState)
{
    uint8_t tmperrorinterrupt = 0;
    CAN_Page_TypeDef can_page = CAN_GetSelectedPage();


    /* Check the parameters */
    assert_param(IS_CAN_IT_CONFIG_OK(CAN_IT));
    assert_param(IS_FUNCTIONALSTATE_OK(NewState));

    tmperrorinterrupt = (uint8_t)(((uint16_t)CAN_IT) >>7);
    tmperrorinterrupt = (uint8_t)((uint8_t)((uint16_t)tmperrorinterrupt & 0xF0) |
                                  (uint8_t)((uint8_t)((uint16_t)tmperrorinterrupt & 0x0F) >>1));

    CAN->PSR = CAN_Page_Config;
    if (NewState != DISABLE)
    {
        /* Enable the selected CAN interrupt */
        CAN->IER |= (uint8_t)(CAN_IT);
        CAN->Page.Config.EIER |= (uint8_t)(tmperrorinterrupt);
    }
    else
    {
        /* Disable the selected CAN interrupt */
        CAN->IER &= (uint8_t)~(uint8_t)((uint16_t)CAN_IT);
        CAN->Page.Config.EIER &= (uint8_t)~(tmperrorinterrupt);
    }
    /*Restore Last Page*/
    CAN_SelectPage(can_page);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。