testa can með l4.4
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/drivers/can.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
/* Devicetree node selected by zephyr,canbus in the overlay */
|
||||
#define CANBUS_NODE DT_CHOSEN(zephyr_canbus)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct device *dev = DEVICE_DT_GET(CANBUS_NODE);
|
||||
|
||||
if (!device_is_ready(dev)) {
|
||||
printk("CAN device not ready\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int err = can_set_bitrate(dev, 125000);
|
||||
if (err != 0) {
|
||||
printk("Error setting CAN bitrate (err %d)\n", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = can_start(dev);
|
||||
if (err != 0) {
|
||||
printk("Error starting CAN controller (err %d)\n", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct can_frame frame = {
|
||||
.flags = 0,
|
||||
.id = 0x123,
|
||||
.dlc = 8,
|
||||
.data = {1, 2, 3, 4, 5, 6, 7, 8},
|
||||
};
|
||||
|
||||
while (1) {
|
||||
k_msleep(500);
|
||||
|
||||
err = can_send(dev, &frame, K_MSEC(100), NULL, NULL);
|
||||
if (err != 0) {
|
||||
printk("Sending failed (err %d)\n", err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
// Change these to see the difference in candump.
|
||||
#define TEST_CAN_ID 0x123 // 11-bit standard id (0x000 - 0x7FF)
|
||||
#define TEST_CAN_DLC 8 // Number of data bytes (0 - 8)
|
||||
#define CAN_BITRATE 250000 // Must match the bitrate of can0 on the Pi
|
||||
#define CAN_BITRATE 125000 // Must match the bitrate of can0 on the Pi
|
||||
|
||||
static const struct device *const can_dev = DEVICE_DT_GET(DT_NODELABEL(can1));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user