6. 报错配置 – 并且已经打开中断
static void CAN1_ErrorNotificationInterruptEnable(void)
{
CAN1_SetInvalidMessageInterruptHandler(DefaultInvalidMessageHandler);
CAN1_SetBusWakeUpActivityInterruptHandler(DefaultBusWakeUpActivityHandler);
CAN1_SetBusErrorInterruptHandler(DefaultBusErrorHandler);
CAN1_SetModeChangeInterruptHandler(DefaultModeChangeHandler);
CAN1_SetSystemErrorInterruptHandler(DefaultSystemErrorHandler);
CAN1_SetTxAttemptInterruptHandler(DefaultTxAttemptHandler);
CAN1_SetRxBufferOverFlowInterruptHandler(DefaultRxBufferOverflowHandler);
PIR0bits.CANIF = 0;
// MODIF disabled; TBCIF disabled;
C1INTL = 0x00;
// IVMIF disabled; WAKIF disabled; CERRIF disabled; SERRIF disabled;
C1INTH = 0x00;
// TEFIE disabled; MODIE enabled; TBCIE disabled; RXIE disabled; TXIE disabled;
C1INTU = 0x08;
// IVMIE enabled; WAKIE enabled; CERRIE enabled; SERRIE enabled; RXOVIE enabled; TXATIE enabled;
C1INTT = 0xFC;
PIE0bits.CANIE = 1;
}
typedef enum
{
/*DLC_0 to DLC_8 for CAN 2.0 and CAN FD*/
DLC_0,
DLC_1,
DLC_2,
DLC_3,
DLC_4,
DLC_5,
DLC_6,
DLC_7,
DLC_8,
//Supported only in CAN FD mode
/*DLC_12 to DLC_64 for CAN FD*/
DLC_12,
DLC_16,
DLC_20,
DLC_24,
DLC_32,
DLC_48,
DLC_64,
} CAN_DLC;
typedef enum
{
CAN_TX_FIFO_FULL,
CAN_TX_FIFO_AVAILABLE,
} CAN_TX_FIFO_STATUS;
typedef enum
{
CAN_OP_MODE_REQUEST_SUCCESS, // Requested Operation mode set successfully
CAN_OP_MODE_REQUEST_FAIL, // Requested Operation mode set failure. Set configuration mode before setting CAN normal or debug operation mode.
CAN_OP_MODE_SYS_ERROR_OCCURED // System error occurred while setting Operation mode.
} CAN_OP_MODE_STATUS;
typedef enum
{
CAN_TX_MSG_REQUEST_SUCCESS = 0, // Transmit message object successfully placed into Transmit FIFO
CAN_TX_MSG_REQUEST_DLC_EXCEED_ERROR = 1, // Transmit message object DLC size is more than Transmit FIFO configured DLC size
CAN_TX_MSG_REQUEST_BRS_ERROR = 2, // Transmit FIFO is configured has Non BRS mode and CAN TX Message object has BRS enabled
CAN_TX_MSG_REQUEST_FIFO_FULL = 3, // Transmit FIFO is Full
}
typedef enum
{
CAN_NORMAL_FD_MODE = 0, //Supported only in CAN FD mode
CAN_DISABLE_MODE = 1,
CAN_INTERNAL_LOOPBACK_MODE = 2,
CAN_LISTEN_ONLY_MODE = 3,
CAN_CONFIGURATION_MODE = 4,
CAN_EXTERNAL_LOOPBACK_MODE = 5,
CAN_NORMAL_2_0_MODE = 6,
CAN_RESTRICTED_OPERATION_MODE =7,
} CAN_OP_MODES;
|