Establish communication via CAN-BUS using Seeed CAN BUS Shield V2.0 & NRF52840DK #73285
Unanswered
sofialibertadmontoya
asked this question in
Q&A
Replies: 0 comments
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.
-
Hi everyone!!
Im very new to this firmware space and would love some help.
Currently I have a NRF52840 DK Board with a Seeed Canbus shield. (CAN-BUS Shield V2.0 | Seeed Studio Wiki)
This shield is very similar to the DFROBOT CanBus Shield. (Only changing the default pinout for the CS from D10 to D9).
Currently I'm trying to be able to send and recieve CAN-BUS frames from other devices to the NRF. When I set the loobback mode it seems to be working but the problem is then when i set it into normal mode to communicate with other devices I get
error <err> main: Sending failed [-11]
.I know that the NRF works with 3.3V power supply and the CAN-BUS Shield works with 5V, so in other forum someone mentioned to do a 3.3V hack as you can see below. That allowed me to compile, flash and run correctly my code in loopback mode.
This is the following code that i've been working with:
`#include <zephyr/drivers/can.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);
void tx_callback(const struct device *dev, int error, void *user_data)
{
char *sender = (char *)user_data;
}
int send_function(const struct device *can_dev)
{
struct can_frame frame = {.flags = 0, .id = 0x7df, .dlc = 8, .data = {0x02, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00}};
}
void rx_callback_function(const struct device *dev, struct can_frame *frame, void *user_data)
{
char *sender = (char *)user_data;
}
int main(void)
{
LOG_INF("CanBus-OBD2 samplev11");
int ret;
k_sleep(K_MSEC(8000));
}`
When I set in LOOPBACK mode i get the following output as you can see below:
[00:00:08.402,130] <inf> main: ------------------------- [00:00:08.402,160] <inf> main: Initializing CAN bus [00:00:08.402,160] <inf> main: Asserting device ready. [00:00:08.402,191] <inf> main: CAN: Device can@0 ready. [00:00:08.402,191] <inf> main: ------------------------- [00:00:08.402,221] <inf> main: Enabling MODE LOOPBACK. [00:00:08.402,221] <inf> main: MODE LOOPBACK. [00:00:08.402,221] <inf> main: ------------------------- [00:00:08.402,252] <inf> main: Trying to set bitrate. [00:00:08.402,557] <inf> main: Bitrate set. [00:00:08.402,587] <inf> main: ------------------------- [00:00:08.402,587] <inf> main: Adding reception filter [00:00:08.402,587] <inf> main: Before adding reception filter. [00:00:08.402,618] <inf> main: RX filter added successfully. Filter ID: 0 [00:00:08.402,618] <inf> main: ------------------------- [00:00:08.402,618] <inf> main: Trying to start CAN. [00:00:08.402,832] <inf> main: CAN started [00:00:08.402,832] <inf> main: ------------------------- [00:00:08.402,832] <inf> main: Waiting for CAN frame [00:00:09.402,923] <inf> main: Sending CAN frame with ID: 0x7df, DLC: 8 [00:00:09.403,228] <inf> main: CAN frame sent [00:00:09.403,228] <inf> main: ** ** ** ** ** ** ** ** [00:00:09.403,808] <inf> main: Message sent successfully - Sender: Sender 1 [00:00:09.403,808] <inf> main: tx_callback executed [00:00:11.403,320] <inf> main: Waiting for CAN frame [00:00:12.403,472] <inf> main: Sending CAN frame with ID: 0x7df, DLC: 8 [00:00:12.403,747] <inf> main: CAN frame sent [00:00:12.403,778] <inf> main: ** ** ** ** ** ** ** ** [00:00:12.404,296] <inf> main: Message sent successfully - Sender: Sender 1 [00:00:12.404,327] <inf> main: tx_callback executed
But then when i set it into NORMAL mode I get the following output:
[00:00:08.434,112] <inf> main: ------------------------- [00:00:08.434,143] <inf> main: Initializing CAN bus [00:00:08.434,143] <inf> main: Asserting device ready. [00:00:08.434,173] <inf> main: CAN: Device can@0 ready. [00:00:08.434,173] <inf> main: ------------------------- [00:00:08.434,204] <inf> main: Enabling MODE NORMAL. [00:00:08.434,204] <inf> main: MODE NORMAL. [00:00:08.434,204] <inf> main: ------------------------- [00:00:08.434,234] <inf> main: Trying to set bitrate. [00:00:08.434,539] <inf> main: Bitrate set. [00:00:08.434,570] <inf> main: ------------------------- [00:00:08.434,570] <inf> main: Adding reception filter [00:00:08.434,570] <inf> main: Before adding reception filter. [00:00:08.434,600] <inf> main: RX filter added successfully. Filter ID: 0 [00:00:08.434,600] <inf> main: ------------------------- [00:00:08.434,600] <inf> main: Trying to start CAN. [00:00:08.434,814] <inf> main: CAN started [00:00:08.434,814] <inf> main: ------------------------- [00:00:08.434,814] <inf> main: Waiting for CAN frame [00:00:09.434,906] <inf> main: Sending CAN frame with ID: 0x7df, DLC: 8 [00:00:09.435,211] <inf> main: CAN frame sent [00:00:09.435,211] <inf> main: ** ** ** ** ** ** ** ** [00:00:11.435,302] <inf> main: Waiting for CAN frame [00:00:12.435,485] <inf> main: Sending CAN frame with ID: 0x7df, DLC: 8 [00:00:17.435,607] <err> main: Sending failed [-11] [00:00:17.435,638] <inf> main: ** ** ** ** ** ** ** ** [00:00:19.435,729] <inf> main: Waiting for CAN frame [00:00:20.435,913] <inf> main: Sending CAN frame with ID: 0x7df, DLC: 8 [00:00:25.436,035] <err> main: Sending failed [-11] [00:00:25.436,065] <inf> main: ** ** ** ** ** ** ** **
I modified the dfrobot_can_bus_v2_0.overlay to make it work with my seeed shield. (changing the CS-GPIOS to 15 (D9) instead of 16 (D10). This is my overlay:
`&arduino_spi {
status = "okay";
cs-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */
};
/ {
chosen {
zephyr,canbus = &mcp2515_dfrobot_can_bus_v2_0;
};
};`
And just in case, my prj.config
`CONFIG_POLL=y
CONFIG_CAN=y
CONFIG_SPI=y
CONFIG_CAN_MCP2515=y
CONFIG_CAN_INIT_PRIORITY=80
CONFIG_CAN_MAX_FILTER=5
CONFIG_SHELL=y
CONFIG_CAN_SHELL=y
CONFIG_DEVICE_SHELL=y
CONFIG_GPIO=y
CONFIG_STATS=y
CONFIG_STATS_NAMES=y
CONFIG_STATS_SHELL=y
CONFIG_CAN_STATS=y
CONFIG_RTT_CONSOLE=n
CONFIG_LOG=y
CONFIG_CAN_LOG_LEVEL_DBG=y
CONFIG_SPI_LOG_LEVEL_DBG=n
CONFIG_PRINTK=y
CONFIG_CONSOLE=y`
Finally this is my build configuration:
I don't really know how to progress on this and would be very grateful I one of you have done this before or have any advice :)
Beta Was this translation helpful? Give feedback.
All reactions