24 #ifndef __STM32F10x_CAN_H 25 #define __STM32F10x_CAN_H 46 #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \ 55 uint16_t CAN_Prescaler;
108 uint16_t CAN_FilterIdHigh;
112 uint16_t CAN_FilterIdLow;
116 uint16_t CAN_FilterMaskIdHigh;
121 uint16_t CAN_FilterMaskIdLow;
126 uint16_t CAN_FilterFIFOAssignment;
129 uint8_t CAN_FilterNumber;
131 uint8_t CAN_FilterMode;
134 uint8_t CAN_FilterScale;
212 #define CAN_InitStatus_Failed ((uint8_t)0x00) 213 #define CAN_InitStatus_Success ((uint8_t)0x01) 223 #define CAN_Mode_Normal ((uint8_t)0x00) 224 #define CAN_Mode_LoopBack ((uint8_t)0x01) 225 #define CAN_Mode_Silent ((uint8_t)0x02) 226 #define CAN_Mode_Silent_LoopBack ((uint8_t)0x03) 228 #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \ 229 ((MODE) == CAN_Mode_LoopBack)|| \ 230 ((MODE) == CAN_Mode_Silent) || \ 231 ((MODE) == CAN_Mode_Silent_LoopBack)) 241 #define CAN_OperatingMode_Initialization ((uint8_t)0x00) 242 #define CAN_OperatingMode_Normal ((uint8_t)0x01) 243 #define CAN_OperatingMode_Sleep ((uint8_t)0x02) 246 #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\ 247 ((MODE) == CAN_OperatingMode_Normal)|| \ 248 ((MODE) == CAN_OperatingMode_Sleep)) 258 #define CAN_ModeStatus_Failed ((uint8_t)0x00) 259 #define CAN_ModeStatus_Success ((uint8_t)!CAN_ModeStatus_Failed) 270 #define CAN_SJW_1tq ((uint8_t)0x00) 271 #define CAN_SJW_2tq ((uint8_t)0x01) 272 #define CAN_SJW_3tq ((uint8_t)0x02) 273 #define CAN_SJW_4tq ((uint8_t)0x03) 275 #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \ 276 ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq)) 285 #define CAN_BS1_1tq ((uint8_t)0x00) 286 #define CAN_BS1_2tq ((uint8_t)0x01) 287 #define CAN_BS1_3tq ((uint8_t)0x02) 288 #define CAN_BS1_4tq ((uint8_t)0x03) 289 #define CAN_BS1_5tq ((uint8_t)0x04) 290 #define CAN_BS1_6tq ((uint8_t)0x05) 291 #define CAN_BS1_7tq ((uint8_t)0x06) 292 #define CAN_BS1_8tq ((uint8_t)0x07) 293 #define CAN_BS1_9tq ((uint8_t)0x08) 294 #define CAN_BS1_10tq ((uint8_t)0x09) 295 #define CAN_BS1_11tq ((uint8_t)0x0A) 296 #define CAN_BS1_12tq ((uint8_t)0x0B) 297 #define CAN_BS1_13tq ((uint8_t)0x0C) 298 #define CAN_BS1_14tq ((uint8_t)0x0D) 299 #define CAN_BS1_15tq ((uint8_t)0x0E) 300 #define CAN_BS1_16tq ((uint8_t)0x0F) 302 #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq) 311 #define CAN_BS2_1tq ((uint8_t)0x00) 312 #define CAN_BS2_2tq ((uint8_t)0x01) 313 #define CAN_BS2_3tq ((uint8_t)0x02) 314 #define CAN_BS2_4tq ((uint8_t)0x03) 315 #define CAN_BS2_5tq ((uint8_t)0x04) 316 #define CAN_BS2_6tq ((uint8_t)0x05) 317 #define CAN_BS2_7tq ((uint8_t)0x06) 318 #define CAN_BS2_8tq ((uint8_t)0x07) 320 #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq) 330 #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024)) 340 #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 13) 342 #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27) 352 #define CAN_FilterMode_IdMask ((uint8_t)0x00) 353 #define CAN_FilterMode_IdList ((uint8_t)0x01) 355 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \ 356 ((MODE) == CAN_FilterMode_IdList)) 365 #define CAN_FilterScale_16bit ((uint8_t)0x00) 366 #define CAN_FilterScale_32bit ((uint8_t)0x01) 368 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \ 369 ((SCALE) == CAN_FilterScale_32bit)) 379 #define CAN_Filter_FIFO0 ((uint8_t)0x00) 380 #define CAN_Filter_FIFO1 ((uint8_t)0x01) 381 #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \ 382 ((FIFO) == CAN_FilterFIFO1)) 390 #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27)) 399 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02)) 400 #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF)) 401 #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF)) 402 #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08)) 412 #define CAN_Id_Standard ((uint32_t)0x00000000) 413 #define CAN_Id_Extended ((uint32_t)0x00000004) 414 #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \ 415 ((IDTYPE) == CAN_Id_Extended)) 424 #define CAN_RTR_Data ((uint32_t)0x00000000) 425 #define CAN_RTR_Remote ((uint32_t)0x00000002) 426 #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote)) 436 #define CAN_TxStatus_Failed ((uint8_t)0x00) 437 #define CAN_TxStatus_Ok ((uint8_t)0x01) 438 #define CAN_TxStatus_Pending ((uint8_t)0x02) 439 #define CAN_TxStatus_NoMailBox ((uint8_t)0x04) 449 #define CAN_FIFO0 ((uint8_t)0x00) 450 #define CAN_FIFO1 ((uint8_t)0x01) 452 #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1)) 462 #define CAN_Sleep_Failed ((uint8_t)0x00) 463 #define CAN_Sleep_Ok ((uint8_t)0x01) 473 #define CAN_WakeUp_Failed ((uint8_t)0x00) 474 #define CAN_WakeUp_Ok ((uint8_t)0x01) 485 #define CAN_ErrorCode_NoErr ((uint8_t)0x00) 486 #define CAN_ErrorCode_StuffErr ((uint8_t)0x10) 487 #define CAN_ErrorCode_FormErr ((uint8_t)0x20) 488 #define CAN_ErrorCode_ACKErr ((uint8_t)0x30) 489 #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40) 490 #define CAN_ErrorCode_BitDominantErr ((uint8_t)0x50) 491 #define CAN_ErrorCode_CRCErr ((uint8_t)0x60) 492 #define CAN_ErrorCode_SoftwareSetErr ((uint8_t)0x70) 507 #define CAN_FLAG_RQCP0 ((uint32_t)0x38000001) 508 #define CAN_FLAG_RQCP1 ((uint32_t)0x38000100) 509 #define CAN_FLAG_RQCP2 ((uint32_t)0x38010000) 512 #define CAN_FLAG_FMP0 ((uint32_t)0x12000003) 513 #define CAN_FLAG_FF0 ((uint32_t)0x32000008) 514 #define CAN_FLAG_FOV0 ((uint32_t)0x32000010) 515 #define CAN_FLAG_FMP1 ((uint32_t)0x14000003) 516 #define CAN_FLAG_FF1 ((uint32_t)0x34000008) 517 #define CAN_FLAG_FOV1 ((uint32_t)0x34000010) 520 #define CAN_FLAG_WKU ((uint32_t)0x31000008) 521 #define CAN_FLAG_SLAK ((uint32_t)0x31000012) 526 #define CAN_FLAG_EWG ((uint32_t)0x10F00001) 527 #define CAN_FLAG_EPV ((uint32_t)0x10F00002) 528 #define CAN_FLAG_BOF ((uint32_t)0x10F00004) 529 #define CAN_FLAG_LEC ((uint32_t)0x30F00070) 531 #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOF) || \ 532 ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_EWG) || \ 533 ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FOV0) || \ 534 ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FMP0) || \ 535 ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1) || \ 536 ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \ 537 ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \ 538 ((FLAG) == CAN_FLAG_SLAK )) 540 #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \ 541 ((FLAG) == CAN_FLAG_RQCP1) || ((FLAG) == CAN_FLAG_RQCP0) || \ 542 ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FOV0) ||\ 543 ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \ 544 ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK)) 556 #define CAN_IT_TME ((uint32_t)0x00000001) 559 #define CAN_IT_FMP0 ((uint32_t)0x00000002) 560 #define CAN_IT_FF0 ((uint32_t)0x00000004) 561 #define CAN_IT_FOV0 ((uint32_t)0x00000008) 562 #define CAN_IT_FMP1 ((uint32_t)0x00000010) 563 #define CAN_IT_FF1 ((uint32_t)0x00000020) 564 #define CAN_IT_FOV1 ((uint32_t)0x00000040) 567 #define CAN_IT_WKU ((uint32_t)0x00010000) 568 #define CAN_IT_SLK ((uint32_t)0x00020000) 571 #define CAN_IT_EWG ((uint32_t)0x00000100) 572 #define CAN_IT_EPV ((uint32_t)0x00000200) 573 #define CAN_IT_BOF ((uint32_t)0x00000400) 574 #define CAN_IT_LEC ((uint32_t)0x00000800) 575 #define CAN_IT_ERR ((uint32_t)0x00008000) 578 #define CAN_IT_RQCP0 CAN_IT_TME 579 #define CAN_IT_RQCP1 CAN_IT_TME 580 #define CAN_IT_RQCP2 CAN_IT_TME 583 #define IS_CAN_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0) ||\ 584 ((IT) == CAN_IT_FF0) || ((IT) == CAN_IT_FOV0) ||\ 585 ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1) ||\ 586 ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG) ||\ 587 ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\ 588 ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\ 589 ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK)) 591 #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0) ||\ 592 ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1) ||\ 593 ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG) ||\ 594 ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\ 595 ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\ 596 ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK)) 605 #define CANINITFAILED CAN_InitStatus_Failed 606 #define CANINITOK CAN_InitStatus_Success 607 #define CAN_FilterFIFO0 CAN_Filter_FIFO0 608 #define CAN_FilterFIFO1 CAN_Filter_FIFO1 609 #define CAN_ID_STD CAN_Id_Standard 610 #define CAN_ID_EXT CAN_Id_Extended 611 #define CAN_RTR_DATA CAN_RTR_Data 612 #define CAN_RTR_REMOTE CAN_RTR_Remote 613 #define CANTXFAILE CAN_TxStatus_Failed 614 #define CANTXOK CAN_TxStatus_Ok 615 #define CANTXPENDING CAN_TxStatus_Pending 616 #define CAN_NO_MB CAN_TxStatus_NoMailBox 617 #define CANSLEEPFAILED CAN_Sleep_Failed 618 #define CANSLEEPOK CAN_Sleep_Ok 619 #define CANWAKEUPFAILED CAN_WakeUp_Failed 620 #define CANWAKEUPOK CAN_WakeUp_Ok uint8_t CAN_Init(CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
uint8_t CAN_GetLastErrorCode(CAN_TypeDef *CANx)
Returns the CANx's last error code (LEC).
void CAN_ITConfig(CAN_TypeDef *CANx, uint32_t CAN_IT, FunctionalState NewState)
Enables or disables the specified CANx interrupts.
uint8_t CAN_MessagePending(CAN_TypeDef *CANx, uint8_t FIFONumber)
Returns the number of pending received messages.
CAN init structure definition.
uint8_t CAN_Sleep(CAN_TypeDef *CANx)
Enters the Sleep (low power) mode.
uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef *CANx)
Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
FlagStatus CAN_GetFlagStatus(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Checks whether the specified CAN flag is set or not.
uint8_t CAN_OperatingModeRequest(CAN_TypeDef *CANx, uint8_t CAN_OperatingMode)
Selects the CAN Operation mode.
uint8_t CAN_Transmit(CAN_TypeDef *CANx, CanTxMsg *TxMessage)
Initiates and transmits a CAN frame message.
void CAN_Receive(CAN_TypeDef *CANx, uint8_t FIFONumber, CanRxMsg *RxMessage)
Receives a correct CAN frame.
void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct)
Fills each CAN_InitStruct member with its default value.
uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef *CANx)
Returns the CANx Receive Error Counter (REC).
void CAN_ClearFlag(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Clears the CAN's pending flags.
void CAN_DBGFreeze(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the DBG Freeze for CAN.
uint8_t CAN_TransmitStatus(CAN_TypeDef *CANx, uint8_t TransmitMailbox)
Checks the transmission status of a CAN Frame.
void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
Select the start bank filter for slave CAN.
void CAN_CancelTransmit(CAN_TypeDef *CANx, uint8_t Mailbox)
Cancels a transmit request.
CAN filter init structure definition.
void CAN_ClearITPendingBit(CAN_TypeDef *CANx, uint32_t CAN_IT)
Clears the CANx's interrupt pending bits.
CAN Tx message structure definition.
uint8_t CAN_WakeUp(CAN_TypeDef *CANx)
Wakes up the CAN peripheral from sleep mode .
CMSIS Cortex-M3 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...
void CAN_FIFORelease(CAN_TypeDef *CANx, uint8_t FIFONumber)
Releases the specified receive FIFO.
void CAN_TTComModeCmd(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the CAN Time TriggerOperation communication mode.
void CAN_DeInit(CAN_TypeDef *CANx)
Deinitializes the CAN peripheral registers to their default reset values.
ITStatus CAN_GetITStatus(CAN_TypeDef *CANx, uint32_t CAN_IT)
Checks whether the specified CANx interrupt has occurred or not.
void CAN_FilterInit(CAN_FilterInitTypeDef *CAN_FilterInitStruct)
Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct...
CAN Rx message structure definition.