can-fd-configuration-8.ino
Initializes the CAN FD bus at differentiated speeds (arbitration and data) and sends a standard frame.
Requires HPMicro SDK. CAN FD allows up to 8 Mbps in the data phase. Ensure you have a 120 Ohm bus termination and an external CAN transceiver connected to the HPM5100.
can-fd-configuration-8.ino
#include "board.h"
#include "hpm_canfd_drv.h"
#include "hpm_clock_drv.h"
#define CANFD_SAMPLE_POINT 80
#define CANFD_TSEG1 12
#define CANFD_TSEG2 3
canfd_buf_config_t tx_buf_cfg;
canfd_message_t rx_msg, tx_msg;
void canfd_setup(void)
{
canfd_config_t canfd_config;
clock_add_to_group(clock_can0, 0);
/* Configuration CAN FD : 500 kbps Arbitration, 2 Mbps Data */
canfd_config.sample_point = CANFD_SAMPLE_POINT;
canfd_config.tseg1 = CANFD_TSEG1;
canfd_config.tseg2 = CANFD_TSEG2;
canfd_config.sample_point_data = CANFD_SAMPLE_POINT;
canfd_config.tseg1_data = CANFD_TSEG1;
canfd_config.tseg2_data = CANFD_TSEG2;
canfd_config.mode = canfd_mode_normal;
canfd_init(CAN0, &canfd_config);
/* Configuration buffer TX */
tx_buf_cfg.data_size = 64; /* Max Data Size CAN FD */
canfd_setup_tx_buffer(CAN0, 0, &tx_buf_cfg);
}
void canfd_send_test(void)
{
tx_msg.id = 0x123;
tx_msg.is_fd = true;
tx_msg.data_len = 8;
tx_msg.data[0] = 0xDE;
tx_msg.data[1] = 0xAD;
/* ... remplir les autres octets ... */
canfd_send_message(CAN0, 0, &tx_msg);
}
int main(void)
{
board_init();
canfd_setup();
while (1) {
canfd_send_test();
delay_ms(100);
}
}