<alp/can.h> — CAN / CAN-FD
Controller Area Network bus support, including CAN-FD on hardware that supports it.
Header
#include <alp/can.h>
Send and receive
alp_can_t *can = alp_can_open(&(alp_can_config_t){
.bus_id = ALP_E1M_CAN0,
.bitrate_nominal_hz = 500000, // arbitration phase
.bitrate_data_hz = 2000000, // CAN-FD data phase
.mode = ALP_CAN_MODE_FD,
});
alp_can_start(can);
alp_can_frame_t tx = {
.id = 0x123,
.ext_id = false,
.dlc = 8,
.data = { 1, 2, 3, 4, 5, 6, 7, 8 },
};
alp_can_send(can, &tx, /* timeout_ms */ 100);
void on_frame(const alp_can_frame_t *f, void *user) { /* ... */ }
alp_can_add_filter(can,
&(alp_can_filter_t){ .id = 0x123, .mask = 0x7FF },
on_frame, NULL, /* filter_id_out */ NULL);
See also
Questions about this page? Discuss in Community Forum