86 #include "stm32f4xx_rcc.h" 100 #define MCR_DBF ((uint32_t)0x00010000) 103 #define TMIDxR_TXRQ ((uint32_t)0x00000001) 106 #define FMR_FINIT ((uint32_t)0x00000001) 109 #define INAK_TIMEOUT ((uint32_t)0x0000FFFF) 111 #define SLAK_TIMEOUT ((uint32_t)0x0000FFFF) 114 #define CAN_FLAGS_TSR ((uint32_t)0x08000000) 116 #define CAN_FLAGS_RF1R ((uint32_t)0x04000000) 118 #define CAN_FLAGS_RF0R ((uint32_t)0x02000000) 120 #define CAN_FLAGS_MSR ((uint32_t)0x01000000) 122 #define CAN_FLAGS_ESR ((uint32_t)0x00F00000) 125 #define CAN_TXMAILBOX_0 ((uint8_t)0x00) 126 #define CAN_TXMAILBOX_1 ((uint8_t)0x01) 127 #define CAN_TXMAILBOX_2 ((uint8_t)0x02) 129 #define CAN_MODE_MASK ((uint32_t) 0x00000003) 200 uint32_t wait_ack = 0x00000000;
295 CANx->
BTR = (uint32_t)((uint32_t)CAN_InitStruct->
CAN_Mode << 30) | \
296 ((uint32_t)CAN_InitStruct->
CAN_SJW << 24) | \
297 ((uint32_t)CAN_InitStruct->
CAN_BS1 << 16) | \
298 ((uint32_t)CAN_InitStruct->
CAN_BS2 << 20) | \
336 uint32_t filter_number_bit_pos = 0;
344 filter_number_bit_pos = ((uint32_t)1) << CAN_FilterInitStruct->
CAN_FilterNumber;
350 CAN1->FA1R &= ~(uint32_t)filter_number_bit_pos;
356 CAN1->FS1R &= ~(uint32_t)filter_number_bit_pos;
374 CAN1->FS1R |= filter_number_bit_pos;
389 CAN1->FM1R &= ~(uint32_t)filter_number_bit_pos;
394 CAN1->FM1R |= (uint32_t)filter_number_bit_pos;
401 CAN1->FFA1R &= ~(uint32_t)filter_number_bit_pos;
407 CAN1->FFA1R |= (uint32_t)filter_number_bit_pos;
413 CAN1->FA1R |= filter_number_bit_pos;
477 CAN1->FMR &= (uint32_t)0xFFFFC0F1 ;
478 CAN1->FMR |= (uint32_t)(CAN_BankNumber)<<8;
579 uint8_t transmit_mailbox = 0;
589 transmit_mailbox = 0;
593 transmit_mailbox = 1;
597 transmit_mailbox = 2;
623 TxMessage->
DLC &= (uint8_t)0x0000000F;
629 ((uint32_t)TxMessage->
Data[2] << 16) |
630 ((uint32_t)TxMessage->
Data[1] << 8) |
631 ((uint32_t)TxMessage->
Data[0]));
633 ((uint32_t)TxMessage->
Data[6] << 16) |
634 ((uint32_t)TxMessage->
Data[5] << 8) |
635 ((uint32_t)TxMessage->
Data[4]));
639 return transmit_mailbox;
657 switch (TransmitMailbox)
694 return (uint8_t) state;
824 uint8_t message_pending=0;
830 message_pending = (uint8_t)(CANx->
RF0R&(uint32_t)0x03);
834 message_pending = (uint8_t)(CANx->
RF1R&(uint32_t)0x03);
840 return message_pending;
970 return (uint8_t)sleepstatus;
1000 return (uint8_t)wakeupstatus;
1042 uint8_t errorcode=0;
1300 CANx->
IER |= CAN_IT;
1305 CANx->
IER &= ~CAN_IT;
1342 if ((CANx->
ESR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1356 if ((CANx->
MSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1370 if ((CANx->
TSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1384 if ((CANx->
RF0R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1398 if ((uint32_t)(CANx->
RF1R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1444 flagtmp = CAN_FLAG & 0x000FFFFF;
1449 CANx->
RF0R = (uint32_t)(flagtmp);
1454 CANx->
RF1R = (uint32_t)(flagtmp);
1459 CANx->
TSR = (uint32_t)(flagtmp);
1464 CANx->
MSR = (uint32_t)(flagtmp);
1676 if ((CAN_Reg & It_Bit) != (uint32_t)
RESET)
1679 pendingbitstatus =
SET;
1684 pendingbitstatus =
RESET;
1686 return pendingbitstatus;
#define IS_CAN_BANKNUMBER(BANKNUMBER)
#define IS_CAN_FILTER_FIFO(FIFO)
#define CAN_InitStatus_Failed
CAN init structure definition.
uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef *CANx)
Returns the CANx Receive Error Counter (REC).
uint8_t CAN_Init(CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
#define IS_CAN_OPERATING_MODE(MODE)
FunctionalState CAN_FilterActivation
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_ClearITPendingBit(CAN_TypeDef *CANx, uint32_t CAN_IT)
Clears the CANx's interrupt pending bits.
uint16_t CAN_FilterIdHigh
void CAN_DeInit(CAN_TypeDef *CANx)
Deinitializes the CAN peripheral registers to their default reset values.
void assert_param(int val)
uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef *CANx)
Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
#define CAN_OperatingMode_Normal
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.
#define IS_FUNCTIONAL_STATE(STATE)
static volatile uint8_t * status
ITStatus CAN_GetITStatus(CAN_TypeDef *CANx, uint32_t CAN_IT)
Checks whether the specified CANx interrupt has occurred or not.
static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit)
Checks whether the CAN interrupt has occurred or not.
#define IS_CAN_ALL_PERIPH(PERIPH)
#define IS_CAN_GET_FLAG(FLAG)
uint8_t CAN_WakeUp(CAN_TypeDef *CANx)
Wakes up the CAN peripheral from sleep mode .
This file contains all the functions prototypes for the CAN firmware library.
void CAN_FilterInit(CAN_FilterInitTypeDef *CAN_FilterInitStruct)
Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct...
void CAN_FIFORelease(CAN_TypeDef *CANx, uint8_t FIFONumber)
Releases the specified receive FIFO.
uint8_t CAN_TransmitStatus(CAN_TypeDef *CANx, uint8_t TransmitMailbox)
Checks the transmission status of a CAN Frame.
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
#define IS_CAN_MODE(MODE)
#define IS_CAN_CLEAR_FLAG(FLAG)
#define IS_CAN_IDTYPE(IDTYPE)
#define CAN_OperatingMode_Sleep
void CAN_ClearFlag(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Clears the CAN's pending flags.
uint8_t CAN_Sleep(CAN_TypeDef *CANx)
Enters the Sleep (low power) mode.
#define IS_CAN_STDID(STDID)
FlagStatus CAN_GetFlagStatus(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Checks whether the specified CAN flag is set or not.
#define CAN_TxStatus_NoMailBox
#define IS_CAN_CLEAR_IT(IT)
#define IS_CAN_FILTER_NUMBER(NUMBER)
void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct)
Fills each CAN_InitStruct member with its default value.
#define IS_CAN_EXTID(EXTID)
#define CAN_TxStatus_Pending
#define IS_CAN_PRESCALER(PRESCALER)
#define IS_CAN_FILTER_SCALE(SCALE)
void CAN_TTComModeCmd(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the CAN Time TriggerOperation communication mode.
#define CAN_TxStatus_Failed
uint16_t CAN_FilterFIFOAssignment
#define CAN_FilterScale_32bit
#define IS_CAN_FILTER_MODE(MODE)
#define RCC_APB1Periph_CAN2
CAN filter init structure definition.
void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
Select the start bank filter for slave CAN.
CAN Tx message structure definition.
uint16_t CAN_FilterMaskIdHigh
#define CAN_ModeStatus_Failed
#define CAN_WakeUp_Failed
CAN_FIFOMailBox_TypeDef sFIFOMailBox[2]
#define CAN_FilterMode_IdMask
#define IS_CAN_FIFO(FIFO)
uint8_t CAN_MessagePending(CAN_TypeDef *CANx, uint8_t FIFONumber)
Returns the number of pending received messages.
#define CAN_OperatingMode_Initialization
#define CAN_ModeStatus_Success
uint16_t CAN_FilterMaskIdLow
#define CAN_InitStatus_Success
#define RCC_APB1Periph_CAN1
CAN_TxMailBox_TypeDef sTxMailBox[3]
void CAN_CancelTransmit(CAN_TypeDef *CANx, uint8_t Mailbox)
Cancels a transmit request.
void CAN_DBGFreeze(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the DBG Freeze for CAN.
#define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX)
CAN Rx message structure definition.
#define CAN_FilterScale_16bit