Replies: 1 comment
-
@CEmir10 Please reformat the code to make it readable in the GitHub web view. Please include a dump of the CAN traffic and the expected traffic. I have no way of debugging what is going on with the information provided so far. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to receive messages from pc on my sensor node which uses atmel chip. At the beginning, 2-3 seconds I see some strange values(not the one i am sending) and then i see bus off. This down below is my code:
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/device.h>
#include <zephyr/drivers/can.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/byteorder.h>
CAN_MSGQ_DEFINE(my_can_msgq, 512);
void main(void)
{
const struct device *can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
#ifdef CONFIG_NORMAL_MODE
int ret = can_set_mode(can_dev, CAN_NORMAL_MODE);
if (ret != 0) {
printk("Error setting CAN mode [%d]", ret);
return;
}
#endif
const struct zcan_filter my_filter = {
.id_type = CAN_STANDARD_IDENTIFIER,
.rtr = CAN_DATAFRAME,
.id = 0x312,
.rtr_mask = 1,
.id_mask = CAN_STD_ID_MASK
};
struct zcan_frame rx_frame;
int filter_id;
filter_id = can_add_rx_filter_msgq(can_dev, &my_can_msgq, &my_filter);
if (filter_id < 0) {
printk("Unable to add rx msgq [%d]", filter_id);
return;
}
while (true) {
k_msgq_get(&my_can_msgq, &rx_frame, K_FOREVER);
printk("Counter received: %u\n",
sys_be16_to_cpu(UNALIGNED_GET((uint16_t *)&rx_frame.data)));
printk("length %u\n",&rx_frame.dlc);
}
}
Beta Was this translation helpful? Give feedback.
All reactions