CAN Controller Driver function reference
pic18f26k83_can.h
Functions
void pic18f26k83_can_init(const can_timing_t *timing, void (*receive_callback)(const can_msg_t *message)) : Initialize PIC18F26K83 CAN Controller.
Warning
Note that this function DOES NOT setup the inputs and outputs from the CAN module to the output pins, application code must do that. In order to do that, CANRXPPS must be set to the proper pin value for the CANRX pin, and \_\_\_PPS must be set to 0x33 to mark it as outputting from the CAN module. In addition, TRIS and ANSEL registers for whatever pin is being used must be set to the right values.
Parameters:
: - **timing** – Timing parameters generated by `can_generate_timing_params` function
- **receive\_callback** – CAN message receive handler, the function would be called when a CAN message is receivedvoid pic18f26k83_can_send(const can_msg_t *message) : Send a CAN message.
Parameters:
: **message** – CAN message to be sentbool pic18f26k83_can_send_rdy(void) : Check if CAN controller is ready to send a message.
Returns:
: return `true` if ready to send a messagevoid pic18f26k83_can_handle_interrupt(void) : Call this function in an interrupt context whenever PIR5 is nonzero.
Note
This function clears PIR5 interrupt flagspic18f26k83_can_timing_util.h
Defines
CAN_BIT_TIME_US
Functions
w_status_t pic18f26k83_can_generate_timing_params(uint32_t system_freq, can_timing_t *timing) : Generate CAN bus timing setting for PIC microcontrollers.
Parameters:
: - **system\_freq** – PIC Fosc frequency in Hz
- **timing** – buffer to write timing parameters to
Returns:
: `W_SUCCESS` if system\_freq is valid and parameters have been written to `timing`struct can_timing_t : Public Members
uint8\_t brp
uint8\_t sjw
uint8\_t sam
uint8\_t seg1ph
uint8\_t seg2ph
uint8\_t prseg
bool btlmodestm32_can.h
Functions
bool stm32_can_init(FDCAN_HandleTypeDef *handle, void (*receive_callback)(const can_msg_t *message)) : Start STM32 CAN Controller.
Note
This depends on STM32CubeMX generated HAL code has already initialized CAN controller
Parameters:
: - **handle** – pointer to FDCAN\_HandleTypeDef struct in `main.c`
- **receive\_callback** – CAN message receive handler, the function would be called when a CAN message is received
Returns:
: `true` if succeedbool stm32_can_send(const can_msg_t *message) : Send a CAN message.
Parameters:
: **message** – CAN message to be sent
Returns:
: `true` if succeedbool stm32_can_send_rdy(void) : Check if CAN controller is ready to send a message.
Returns:
: `true` if ready to send a messagemcp2515.h
Functions
void mcp2515_can_init(can_timing_t *timing, uint8_t (*spi_read_fcn)(void), void (*spi_write_fcn)(uint8_t data), void (*cs_drive_fcn)(uint8_t state)) : Initialize MCP2515 CAN Controller.
Parameters:
: - **timing** – Timing parameters generated by `can_generate_timing_params` function
- **spi\_read\_fcn** – Function to read 8 bits from SPI bus
- **spi\_write\_fcn** – Function to write 8 bits to SPI bus
- **cs\_drive\_fcn** – Function to drive SPI Chip Select signal to `state` logic levelvoid mcp2515_can_send(can_msg_t *message) : Send a CAN message.
Parameters:
: **message** – CAN message to be sentbool mcp2515_can_send_rdy(void) : Check if CAN controller is ready to send a message.
Returns:
: return `true` if ready to send a messagebool mcp2515_can_receive(can_msg_t *message) : Attempt to receive a CAN message.
Parameters:
: **message** – CAN message receive buffer
Returns:
: return `true` if a message is received