canfd-motor-command.ino

BeagleConnect QuadESC: 4-Channel BLDC Controller · File : canfd-motor-command.ino · Language : C · Use case : Envoyer une commande de couple moteur via bus CAN FD.

CAN FD bus initialization and periodic motor control frame transmission.

Requires connected CAN FD transceiver. Configures arbitration and data bitrates. CAN_H/L pins must be correctly wired. Verify reception on external CAN tool.

canfd-motor-command.ino

#include <zephyr/kernel.h>
#include <zephyr/drivers/can.h>

#define CAN_NODE DT_ALIAS(can0)
static const struct device *can_dev = DEVICE_DT_GET(CAN_NODE);
struct can_frame can_msg = { .can_id = 0x100, .len = 8, .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };

void main(void) {
    can_set_bitrate(can_dev, 500000, 2000000); // 500k arb, 2M data
    if (can_enable(can_dev, CAN_MODE_NORMAL)) return;
    while (1) {
        can_msg.data[0] = 0x01; // Motor ID
        can_msg.data[1] = 0x10; // Torque value
        can_send(can_dev, &can_msg, K_MSEC(100), NULL, NULL);
        k_msleep(10);
    }
}

← Back to the board