nrf9160dk_nrf9160 v0.9.0 mcp2515 canbus decoding problems (SPI is working)

This is the next step of the process getting the canbus working with nrf9160 and the aditional MKR CAN shield from arduino


previus part can be read here 

https://devzone.nordicsemi.com/f/nordic-q-a/81754/nrf9160dk_nrf9160-v0-9-0-v1-7-1-mcp2515-canbus-build-problems


As requested from the previus ticket i have checked the SPI bus and it seems to work.


This is the text on the terminal:

[00:00:00.201,599] <dbg> mcp2515_can.socket_can_init: Init socket CAN device 0x2a698 (SOCKET_CAN_1) for dev 0x2a6c8 (CAN_1)
[00:00:00.217,041] <dbg> net_core.net_init: (main): Priority 90
[00:00:00.225,646] <dbg> net_core.l3_init: (main): Network L3 init done
[00:00:00.234,954] <dbg> mcp2515_can.socket_can_iface_init: Init CAN interface 0x20014a08 dev 0x2a698
uart:~$ *** Booting Zephyr OS build v2.7.0-ncs1  ***
[00:00:00.251,403] <inf> net_socket_can_sample: sleeping for 5 seconds
[00:00:05.260,772] <dbg> net_ctx.net_context_bind: (main): Context 0x200154d8 binding to 1 iface[2] 0x20014a08
[00:00:05.273,559] <dbg> net_conn.conn_register_debug: (main): [0x20015974/1/4/0x05] remote -/0
[00:00:05.285,064] <dbg> net_conn.conn_register_debug: (main):   local ?/0 cb 0x17931 ud (nil)
[00:00:05.296,417] <dbg> net_sock_can.can_register_filters: (main): Registering 1 filters
[00:00:05.307,281] <dbg> net_sock_can.can_register_receiver: (main): Max 1 receivers
[00:00:05.317,840] <dbg> net_socket_can_sample.setup_socket: Started socket CAN TX thread
[00:00:05.328,704] <inf> net_socket_can_sample: 1st RX fd 0
[00:00:05.336,975] <inf> net_socket_can_sample: caaling rx command
[00:00:05.345,855] <dbg> net_socket_can_sample.rx: [0] Waiting CAN data...
[00:00:06.317,871] <dbg> net_socket_can_sample.tx: Sending CAN data...



  • Hello Tomas,

    Thanks a lot for the detailed feedback!

    T.B-D said:
    If no filter is set the MCU recive all data.

    I connected my MKR CAN shield  to my MRK1500 and i reciving this data fom my machine.
    (So i expect the same in the Socket CAN sample.)

    Regarding having the 

    Please note that the Socket CAN sample filters all incoming messages by default, except standard frame with ID 0x1. I can see that the filter is present in the application you shared in the previous case as well. From the log you provided I’m not able to see any frame with this ID.

    T.B-D said:
    Is the overlay correct ?

    Yes, it looks correct to me. But I’m not able to say anything about the external oscillator frequency, neither the bit segments. They should be aligned to the CAN shield & bus configuration.

    How is your CAN bus generally designed and set up?

    Regards,

    Markus

  • This is the code for the arduino example im running,
    github.com/.../MCP2515.h

    Yes, it looks correct to me. But I’m not able to say anything about the external oscillator frequency, neither the bit segments. They should be aligned to the CAN shield & bus configuration.

    How is your CAN bus generally designed and set up?

    oscillator frequency: #define MCP2515_DEFAULT_CLOCK_FREQUENCY 16e6

    My overlay is a copy i found in DevZone.
    Where do i find the information for the values marked with ? bellow.

    reg = <0x0>; --?
    osc-freq = <16000000>;  --OK
    bus-speed = <250000>;  --OK 
    sjw = <1>;  --?
    prop-seg = <2>;  --?
    phase-seg1 = <7>;  --?
    phase-seg2 = <6>;  --?
    #address-cells = <1>;  --?
    #size-cells = <0>;  --?

    If above values is wrong , will i still be abel to inizialse as bellow ? 

    [00:00:00.201,599] <dbg> mcp2515_can.socket_can_init: Init socket CAN device 0x2                                                                                                                                                             a698 (SOCKET_CAN_1) for dev 0x2a6c8 (CAN_1)
    [00:00:00.217,254] <dbg> net_core.net_init: (main): Priority 90
    [00:00:00.225,860] <dbg> net_core.l3_init: (main): Network L3 init done
    [00:00:00.235,168] <dbg> mcp2515_can.socket_can_iface_init: Init CAN interface 0                                                                                                                                                             x20014a08 dev 0x2a698
    uart:~$ *** Booting Zephyr OS build v2.7.0-ncs1  ***
    [00:00:00.251,617] <inf> net_socket_can_sample: sleeping for 5 seconds
    [00:00:05.260,986] <dbg> net_ctx.net_context_bind: (main): Context 0x200154d8 binding to 1 iface[2] 0x20014a08
    [00:00:05.273,742] <dbg> net_conn.conn_register_debug: (main): [0x20015974/1/4/0x05] remote -/0
    [00:00:05.285,217] <dbg> net_conn.conn_register_debug: (main):   local ?/0 cb 0x17931 ud (nil)
    [00:00:05.296,569] <dbg> net_sock_can.can_register_filters: (main): Registering 1 filters
    [00:00:05.307,434] <dbg> net_sock_can.can_register_receiver: (main): Max 1 receivers
    [00:00:05.317,993] <dbg> net_socket_can_sample.setup_socket: Started socket CAN TX thread
    [00:00:05.328,857] <inf> net_socket_can_sample: 1st RX fd 0
    [00:00:05.337,127] <inf> net_socket_can_sample: caaling rx command
    [00:00:05.345,977] <dbg> net_socket_can_sample.rx: [0] Waiting CAN data...
    [00:00:06.318,023] <dbg> net_socket_can_sample.tx: Sending CAN data...
    uart:~$
    


    I reprogrammed my arduino to sending this information. But it did not come threw.

      if (!CAN.begin(250E3)) {
        Serial.println("Starting CAN failed!");
        while (1);
      }
    }
    
    void loop() {
    
      Serial.print("Sending standard packet ...");
    
      CAN.beginPacket(0x1F4);
      CAN.write(0xA1);
      CAN.write(0xA2);
      CAN.write(0xA1);
      CAN.write(0x4B);
      CAN.write(0x45);
      CAN.write(0x6B);
      CAN.write(0x85);
      CAN.write(0xC3);
      CAN.endPacket();
    
      Serial.println("done sending package with id 0x1F4");
    
      delay(500);
      
        Serial.print("Sending extended packet ...");
    
      CAN.beginPacket(0x1BCDEF);
      CAN.write(0xA1);
      CAN.write(0xA2);
      CAN.write(0xA1);
      CAN.write(0x4B);
      CAN.write(0x45);
      CAN.write(0x6B);
      CAN.write(0x85);
      CAN.write(0xC3);
      CAN.endPacket();
    
      Serial.println("done sending package with id 0x1BCDEF");
    
      delay(500);


  • Hello Tomas,

    T.B-D said:
    Where do i find the information for the values marked with ? bellow.

    you can check the bit timing values hereBut anyway, it doesn’t matter that much as long as they match with the values of the other devices connected to the CAN bus.

    T.B-D said:
    If above values is wrong , will i still be abel to inizialse as bellow ? 

    All other values should be ok. To verify, you could enable CONFIG_SPI_LOG_LEVEL_DBG and check if any warning or error messages from the SPI drivers appear in the log.

    T.B-D said:
    I reprogrammed my arduino to sending this information. But it did not come threw.

    Which are the ID’s of those CAN frames? It is a little bit hard for me to interpret this as I’m not familiar with the library. But I assume that

    CAN.beginPacket(0x1F4);
    CAN.beginPacket(0x1BCDEF);

    includes both the arbitration + control field?

    How does the physical setup of your CAN bus generally look like? Do you have a connection layout or similar?

    Regards,

    Markus

  • Hi coming back to this topic again...
    Now it seems that i getting something threw the the canbus connections. but it gives an stack owerflow as in the infornation bellow.

    The can transmitter is sending the following data:
    
    
    Received packet with id 0x2F4 and length 8
    A1 A2 A1 4B 45 6B 85 C3 
    
    Received packet with id 0x1 and length 8
    A1 A2 A1 4B 45 6B 85 C3 
    
    Received packet with id 0x2F4 and length 8
    A1 A2 A1 4B 45 6B 85 C3 
    
    Received packet with id 0x1 and length 8
    A1 A2 A1 4B 45 6B 85 C3 
    
    


    I reprogrammed my CAN Transmitter with an extension of 2 seconds and that gave the timedifferns of stack owerflow from the firts test to te second test of 2 seconds as in the log bellow.

    test with can transmitter 
    
    [00:00:00.730,194] <inf> net_socket_can_sample: sleeping for 1 seconds
    [00:00:01.739,593] <dbg> net_ctx.net_context_bind: (main): Context 0x200154d8 binding to 1 iface[2] 0x20014a08
    [00:00:01.752,380] <dbg> net_conn.conn_register_debug: (main): [0x20015974/1/4/0x05] remote -/0
    [00:00:01.763,885] <dbg> net_conn.conn_register_debug: (main):   local ?/0 cb 0x17969 ud (nil)
    [00:00:01.775,238] <dbg> net_sock_can.can_register_filters: (main): Registering 1 filters
    [00:00:01.786,132] <dbg> net_sock_can.can_register_receiver: (main): Max 1 receivers
    [00:00:01.796,661] <dbg> net_socket_can_sample.setup_socket: Started socket CAN TX thread
    [00:00:01.807,556] <inf> net_socket_can_sample: 1st RX fd 0
    [00:00:01.815,826] <inf> net_socket_can_sample: Started CAN application (0)
    [00:00:01.825,469] <inf> net_socket_can_sample: calling rx command
    [00:00:01.834,350] <dbg> net_socket_can_sample.rx: [0] Waiting CAN data...
    [00:00:02.796,722] <dbg> net_socket_can_sample.tx: Sending CAN data...
    [00:00:04.222,686] <err> os: ***** HARD FAULT *****
    [00:00:04.230,651] <err> os:   Fault escalation (see below)
    [00:00:04.239,166] <err> os: ***** USAGE FAULT *****
    [00:00:04.247,070] <err> os:   Stack overflow (context area not valid)
    [00:00:04.256,561] <err> os: r0/a1:  0x00000008  r1/a2:  0x00000000  r2/a3:  0x20017378
    [00:00:04.267,517] <err> os: r3/a4:  0x20017388 r12/ip:  0x007a1200 r14/lr:  0x000117f3
    [00:00:04.278,503] <err> os:  xpsr:  0x61000000
    [00:00:04.285,949] <err> os: Faulting instruction address (r15/pc): 0x00023802
    [00:00:04.296,142] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
    [00:00:04.306,335] <err> os: Current thread: 0x20014510 (unknown)
    [00:00:04.315,368] <err> fatal_error: Resetting system
    uart:~$ ooting Zephyr OS build v2.7.0-ncs1  ***
    Flash regions           Domain          Permissions
    00 01 0x00000 0x10000   Secure          rwxl
    02 31 0x10000 0x100000  Non-Secure      rwxl
    
    Non-secure callable region 0 placed in flash region 1 with size 32.
    
    SRAM region             Domain          Permissions
    00 07 0x00000 0x10000   Secure          rwxl
    08 31 0x10000 0x40000   Non-Secure      rwxl
    
    ***********************************************************************************************************************************
    reprogrammed can transmitter with 2 seconds longer time before sending 
    
    [00:00:00.729,980] <inf> net_socket_can_sample: sleeping for 1 seconds
    [00:00:01.739,349] <dbg> net_ctx.net_context_bind: (main): Context 0x200154d8 binding to 1 iface[2] 0x20014a08
    [00:00:01.752,136] <dbg> net_conn.conn_register_debug: (main): [0x20015974/1/4/0x05] remote -/0
    [00:00:01.763,641] <dbg> net_conn.conn_register_debug: (main):   local ?/0 cb 0x17969 ud (nil)
    [00:00:01.774,993] <dbg> net_sock_can.can_register_filters: (main): Registering 1 filters
    [00:00:01.785,888] <dbg> net_sock_can.can_register_receiver: (main): Max 1 receivers
    [00:00:01.796,417] <dbg> net_socket_can_sample.setup_socket: Started socket CAN TX thread
    [00:00:01.807,312] <inf> net_socket_can_sample: 1st RX fd 0
    [00:00:01.815,551] <inf> net_socket_can_sample: Started CAN application (0)
    [00:00:01.825,225] <inf> net_socket_can_sample: calling rx command
    [00:00:01.834,106] <dbg> net_socket_can_sample.rx: [0] Waiting CAN data...
    [00:00:02.796,447] <dbg> net_socket_can_sample.tx: Sending CAN data...
    [00:00:06.223,937] <err> os: ***** HARD FAULT *****
    [00:00:06.231,903] <err> os:   Fault escalation (see below)
    [00:00:06.240,386] <err> os: ***** USAGE FAULT *****
    [00:00:06.248,291] <err> os:   Stack overflow (context area not valid)
    [00:00:06.257,781] <err> os: r0/a1:  0x00000008  r1/a2:  0x00000000  r2/a3:  0x20017378
    [00:00:06.268,737] <err> os: r3/a4:  0x20017388 r12/ip:  0x007a1200 r14/lr:  0x000117f3
    [00:00:06.279,693] <err> os:  xpsr:  0x61000000
    [00:00:06.287,170] <err> os: Faulting instruction address (r15/pc): 0x00023802
    [00:00:06.297,332] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
    [00:00:06.307,525] <err> os: Current thread: 0x20014510 (unknown)
    [00:00:06.316,558] <err> fatal_error: Resetting system
    uart:~$ ooting Zephyr OS build v2.7.0-ncs1  ***
    Flash regions           Domain          Permissions
    00 01 0x00000 0x10000   Secure          rwxl
    02 31 0x10000 0x100000  Non-Secure      rwxl
    
    Non-secure callable region 0 placed in flash region 1 with size 32.
    
    SRAM region             Domain          Permissions
    00 07 0x00000 0x10000   Secure          rwxl
    08 31 0x10000 0x40000   Non-Secure      rwxl
     

  • Hello Tomas,

    could you add this parameter to your prj.conf, re-run the application and share the log?

    CONFIG_THREAD_NAME=y

    Thanks & regards,

    Markus

Related