I was previously working on a *distributed robotic control system* where multiple robotic arms communicate via *CAN Bus* to coordinate their movements. Each arm operates independently, but they share data like position, load, and speed in real-time using the AVR128DA48 microcontroller and the MCP2515 CAN controller. The idea is for each robot to adjust its movement based on data from the others, ensuring smooth, synchronized operation.
I’ve set up the MC with the MCP2515, using Zephyr OS to manage the CAN communication. The CAN initialization seems successful: the CAN bus is set up with a 500 kbps baud rate, filters are configured to allow messages between the robotic nodes, and the SPI interface between the AVR and MCP2515 is working fine. I’ve confirmed this by monitoring the SPI communication on the scope.
The issue comes when I try to receive messages from other robotic arms. The `can_add_rx_filter()` function is supposed to catch incoming CAN messages, but it always fails with the error code `-ENOBUFS` (No Buffer Space Available). Even though I am certain the messages are being broadcasted from the other nodes, my node doesn’t seem to capture or process them. I’ve tested the wiring and termination, and all other hardware connections look good.
I keep hitting the following log error when I attempt to add the receive filter:
[00:00:01.002] Failed to add filter: -ENOBUFS
This tells me there’s an issue with the buffer allocation for receiving messages, but I’m not sure why this is happening. I’ve checked my memory allocation settings and even tried reducing the number of active filters, but the issue persists.
Ideally, I expect the `can_add_rx_filter()` function to set up a filter that listens for CAN messages with a specific ID (in this case, `0x200`). Once the filter is added, the `can_recv()` function should capture the incoming message, allowing me to process it and adjust the robotic arm’s behavior based on data from the other arms.
CAN_Bus_Communication_Avr128da48.txt
Hi @destynin The issue likely stems from an insufficient number of message buffers. Increase the maximum number of CAN filters by adjusting the `CONFIG_CAN_MAX_FILTER` setting in the Zephyr configuration (`prj.conf`)
Also, try modifying `can_add_rx_filter()` to include a valid callback function for processing messages asynchronously.
and then, ensure there is enough heap memory for the CAN filter buffer. You might need to increase `CONFIG_MAIN_STACK_SIZE` or adjust heap sizes. hope these help.
alright @darkai042 thanks, I’ll try out your guides and will get back to you on my progress.
@darkai042 Hey buddy, thanks I tried it out, and also ensured that the buffer and filter allocation matches my system’s needs.👍🏽
CONTRIBUTE TO THIS THREAD