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 received

void pic18f26k83_can_send(const can_msg_t *message)

Send a CAN message.

Parameters:

message – CAN message to be sent

bool pic18f26k83_can_send_rdy(void)

Check if CAN controller is ready to send a message.

Returns:

return true if ready to send a message

void pic18f26k83_can_handle_interrupt(void)

Call this function in an interrupt context whenever PIR5 is nonzero.

Note

This function clears PIR5 interrupt flags

stm32h7_can.h

Functions

bool stm32h7_can_init(FDCAN_HandleTypeDef *handle, void (*receive_callback)(const can_msg_t *message))

Start STM32H7 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 succeed

bool stm32h7_can_send(const can_msg_t *message)

Send a CAN message.

Parameters:

message – CAN message to be sent

Returns:

true if succeed

bool stm32h7_can_send_rdy(void)

Check if CAN controller is ready to send a message.

Returns:

true if ready to send a message

dspic33e_can.h

Functions

void dspic33e_can_init(const can_timing_t *timing, void (*receive_callback)(const can_msg_t *message), bool run_in_loopback)

Initialize DSPIC33E 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 received

  • run_in_loopback – Run CAN Controller in loopback mode when true

void dspic33e_can_send(const can_msg_t *message)

Send a CAN message.

Parameters:

message – CAN message to be sent

bool dspic33e_can_send_rdy(void)

Check if CAN controller is ready to send a message.

Returns:

return true if ready to send a message

mcp2515.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 level

void mcp2515_can_send(can_msg_t *message)

Send a CAN message.

Parameters:

message – CAN message to be sent

bool mcp2515_can_send_rdy(void)

Check if CAN controller is ready to send a message.

Returns:

return true if ready to send a message

bool 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