新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > STM32中CAN錯誤中斷1

        STM32中CAN錯誤中斷1

        作者: 時間:2016-11-24 來源:網絡 收藏
        void can_signal(void)
        {
        unsigned char data can_irq;
        unsigned char data temp;
        x_wdgtime();
        can_irq = InterruptReg;
        if(can_irq&ALI_Bit)
        { // 仲裁丟失位
        ++al_counter;
        temp=ArbLostCapReg; // 讀仲裁丟失寄存器
        alc_current=temp&0x1F; // 獲得當前仲裁丟失的位置
        }
        if(can_irq & BEI_Bit)
        { // 總線錯誤中斷
        temp=ErrCodeCapReg;
        buse_current=temp&0x3F;
        temp=temp&0xD0; // 獲得總線錯誤的類型
        switch (temp)
        {
        case 0x00: ++bite_counter;
        case 0x40: ++forme_counter;
        case 0x80: ++stuffe_counter;
        case 0xd0: ++othere_counter;
        }
        }
        if(can_irq & EPI_Bit)
        { // 消極錯誤中斷,
        // 接收或發送錯誤計數超過127時,錯誤狀態變為被動錯誤
        if((RxErrCountReg>127)||(TxErrCountReg>127)) errstatus_current=ERR_PASSIVE;
        // 接收或發送錯誤計數回到小于127時,錯誤狀態變為主動錯誤
        if((RxErrCountReg<127)&&(TxErrCountReg<127)) errstatus_current=ERR_ACTIVE;
        }
        if(can_irq & DOI_Bit)
        { // data overflow
        CommandReg = (CDO_Bit|RRB_Bit);
        return;
        }
        if(can_irq&EI_Bit)
        { // 錯誤報警中斷, 這里只對總線關閉錯誤做處理
        if(StatusReg&BS_Bit)
        { // 檢測狀態寄存器的總線狀態位
        ++busoff_counter;
        ModeControlReg = 0x00;
        return;
        }
        }
        if(can_irq & RI_Bit)
        { // 接收數據中斷
        if(StatusReg & DOS_Bit)
        {
        CommandReg = (CDO_Bit|RRB_Bit);
        return;
        }
        can_readmsg();
        return;
        }
        return;
        }



        關鍵詞: STM32CAN錯誤中

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 山东| 体育| 大连市| 全州县| 龙山县| 盖州市| 团风县| 出国| 博爱县| 赤水市| 长治市| 方正县| 汶上县| 即墨市| 武义县| 浮梁县| 启东市| 哈尔滨市| 东辽县| 屯留县| 普兰县| 梁河县| 沂南县| 集安市| 米脂县| 吉安县| 柏乡县| 城口县| 平陆县| 湄潭县| 无为县| 且末县| 嘉祥县| 永年县| 宝应县| 宜丰县| 罗定市| 廉江市| 甘谷县| 正定县| 梅河口市|