78 #include <stm32f4xx.h>
83 #define CARME_CAN_nCAN_INT_PORT GPIOI
84 #define CARME_CAN_nCAN_INT_PIN GPIO_Pin_8
85 #define CARME_CAN_nCAN_IRQn_CH EXTI9_5_IRQn
88 #define CARME_CAN_BAUD_125K 125000
89 #define CARME_CAN_BAUD_250K 250000
90 #define CARME_CAN_BAUD_500K 500000
91 #define CARME_CAN_BAUD_1M 1000000
94 #define CARME_ERROR_CAN CARME_ERROR_CAN_BASE + 0
95 #define CARME_ERROR_CAN_INVALID_BAUDRATE CARME_ERROR_CAN_BASE + 1
96 #define CARME_ERROR_CAN_RXFIFO_EMPTY CARME_ERROR_CAN_BASE + 2
97 #define CARME_ERROR_CAN_INVALID_MODE CARME_ERROR_CAN_BASE + 3
98 #define CARME_ERROR_CAN_INVALID_OPMODE CARME_ERROR_CAN_BASE + 4
99 #define CARME_ERROR_CAN_INVALID_ACCEPTANCE_MODE CARME_ERROR_CAN_BASE + 5
100 #define CARME_ERROR_CAN_ERROR_STATUS CARME_ERROR_CAN_BASE + 6
103 #define CARME_CAN_INT_BUSERR (SJA1000_IER_BEIE)
104 #define CARME_CAN_INT_ARBIT_LOST (SJA1000_IER_ALIE)
105 #define CARME_CAN_INT_PASSIVE (SJA1000_IER_EPIE)
106 #define CARME_CAN_INT_WAKEUP (SJA1000_IER_WUIE)
107 #define CARME_CAN_INT_OVERRUN (SJA1000_IER_DOIE)
108 #define CARME_CAN_INT_ERROR (SJA1000_IER_EIE)
109 #define CARME_CAN_INT_TX (SJA1000_IER_TIE)
110 #define CARME_CAN_INT_RX (SJA1000_IER_RIE)
113 #define CARME_CAN_DF_RESET 0x00
114 #define CARME_CAN_DF_NORMAL 0x01
115 #define CARME_CAN_DF_LISTEN_ONLY 0x02
116 //#define CARME_CAN_DF_SLEEP 0x04
176 extern void CARME_CAN_InitI(uint32_t baud, uint8_t flags, uint32_t interrupts);
191 #ifdef CARME_CAN_DEBUG
193 extern void CARME_CAN_PrintRegisters();
194 extern void CARME_CAN_GetRegisterString(
char* pStr);
198 static __IO uint8_t *SJA1000_CMD = (__IO uint8_t *) (
FSMC_CAN_BASE);
199 static __IO uint8_t *SJA1000_DATA = (__IO uint8_t *) (
FSMC_CAN_BASE + 8);
208 *SJA1000_CMD = registerAddress;
218 *SJA1000_CMD = registerAddress;
219 return *SJA1000_DATA;
uint8_t ERROR_CODES
Error variable.
Information about the acceptance filter.
static ERROR_CODES CARME_CAN_SetErrorWarningLimit(uint8_t limit)
Set the value of the Error Warning Limit Register. The content can only be changed in reset mode...
void CARME_CAN_Init(uint32_t baud, uint8_t flags)
Initialize GPIOs and the CAN-Controller.
static uint8_t CARME_CAN_IsError(void)
Returns 1 if at least one of the error counters has reached or exceeded the value in the Error Warnin...
static void CARME_CAN_GetArbitrationLostCapture(uint8_t *alc)
Get the value of the TX Error Count Register.
static uint8_t CARME_CAN_Read_Register(uint8_t registerAddress)
Reads a value from a SJA1000 register.
struct _CARME_CAN_MESSAGE CARME_CAN_MESSAGE
This struct encapsulates a CAN message.
struct _CARME_CAN_ACCEPTANCE_FILTER CARME_CAN_ACCEPTANCE_FILTER
Information about the acceptance filter.
static void CARME_CAN_GetRxErrCount(uint8_t *count)
Get the value of the RX Error Count Register.
static void CARME_CAN_GetErrorCodeCapture(uint8_t *ecc)
Get the value of the TX Error Count Register.
enum CARME_CAN_ACCEPTANCE_FILTER_MODE afm
ERROR_CODES CARME_CAN_SetAcceptaceFilter(CARME_CAN_ACCEPTANCE_FILTER *af)
ACCEPTANCE FILTER With the help of the acceptance filter the CAN controller is able to allow passing ...
static uint8_t CARME_CAN_IsBusOn(void)
Returns 1 if the CAN Controller is involved in bus activities The Function checks the BS-bit in the ...
CARME_CAN_IRQ_CALLBACKS
Interrupt sources of the CAN-Controller.
void CARME_CAN_RegisterIRQCallback(enum CARME_CAN_IRQ_CALLBACKS id, IRQ_CALLBACK pIRQCallback)
Registers a callback function. Callback functions are called in Interruptmode. Use this function afte...
SJA1000 specific declarations.
CARME_CAN_ACCEPTANCE_FILTER_MODE
Acceptance filter modes.
void CARME_CAN_InitI(uint32_t baud, uint8_t flags, uint32_t interrupts)
Initialize GPIOs and the CAN-Controller.
static void CARME_CAN_Write_Register(uint8_t registerAddress, uint8_t val)
Write a value in a SJA1000 register.
static void CARME_CAN_ClearDataOverrun(void)
Clear Data-Overrun-Bit in the status register of the SJA1000.
static void CARME_CAN_AbortTransmisssion(void)
Cancel a pending transmission request.
ERROR_CODES CARME_CAN_Write(CARME_CAN_MESSAGE *txMsg)
Sends a CAN-Messsage over the CAN-Bus.
static uint8_t CARME_CAN_IsDataOverrun(void)
Returns 1 if an data overrun occurred The Function checks the DOS-bit in the status register of the S...
void CARME_CAN_UnregisterIRQCallback(enum CARME_CAN_IRQ_CALLBACKS id)
Unregisters a callback function. Callback functions are called in Interruptmode.
ERROR_CODES CARME_CAN_GetAcceptaceFilter(CARME_CAN_ACCEPTANCE_FILTER *af)
Get the Acceptance Filter settings.
ERROR_CODES CARME_CAN_Read(CARME_CAN_MESSAGE *rxMsg)
Reads a CAN-Message from the Receive-Buffer. If no message is in the buffer, the function returns CAR...
ERROR_CODES CARME_CAN_SetBaudrate(uint32_t baud)
Set the baudrate for the CAN-Communication.
#define CARME_ERROR_CAN_INVALID_OPMODE
This struct encapsulates a CAN message.
static void CARME_CAN_GetErrorWarningLimit(uint8_t *limit)
Get the value of the Error Warning Limit Register.
void(* IRQ_CALLBACK)()
Pointer to a function.
void CARME_CAN_Interrupt_Handler(void)
This function will be called from the Interrupt-Handler on a CAN-Interrupt. If it was not the EXTI L...
static void CARME_CAN_GetTxErrCount(uint8_t *count)
Get the value of the TX Error Count Register.
ERROR_CODES CARME_CAN_SetMode(uint8_t flags)
Change operating mode from the CAN-Controller.