CAN Driver INIT FAILED with ssp v1.2.1 ?

Hello,
I have a problem with the CAN driver programmed on SSP v1.2.1

I think I have correctly configured properties: 4 mailbox, 500KBds, etc ...

Yet the function:
     _err = g_can0.p_api-> open (g_can0.p_ctrl, g_can0.p_cfg);
     if (_ERR! = SSP_SUCCESS)
     {
         g_ioport.p_api-> pinWrite (Leds.p_leds [RED_LED], IOPORT_LEVEL_LOW);
         while (1);
     }

Always returns the error: SSP_ERR_CAN_INIT_FAILED

I use the S7G2-SK card powered via the USB port (J19).
SSP v1.2.1 e2Studio v5.4.0.018

My application don't use RTOS for this example.

Thank you in advance for your help.

Eric

  • Hi Eric,

    The configuration seems to be correct. Have you configured pins in Pins tab also (Peripherals > Connectivity:CAN > CAN0)? Could you check the contents of CAN0.CTLR, CAN0.STR, CAN0.EIFR and CAN0.ECSR registers right after the open API failed? You may set a breakpoint and use IO Registers tab in Debug perspective.

    Regards,
    adboc
  • In reply to adboc:

    Hi Adboc and thanks for your fast response.

    Yes, Peripherals > Connectivity:CAN > CAN0 is corectly configured.
    But the contents of CAN0.CTLR, CAN0.STR, CAN0.EIFR and CAN0.ECSR registers are all = 0... After breakpoint, like all the others registers ogf CAN0... :(

    I would like to know that I put the command close() before open(), because I noticed that the open function is precompiled in the sequence of init ...

    But even if I do not do this sequence, the write() function does not output anything. I am using a CAN / USB PeakSystem converter connected on J7 of the S7G2-SK card.

    And my callback function is never called ...

    I probably made a mistake ... but which one?

    Best regards,
    Eric
  • In reply to Eric:

    Hi Eric,

    You don't have to call the close function if the driver wasn't opened before. If the open API returns any error code, the write may not output any data.

    Is my understanding correct, that you still observe SSP_ERR_CAN_INIT_FAILED from the open API?

    Regards,
    adboc
  • In reply to adboc:

    Yes, I still observe SSP_ERR_CAN_INIT_FAILED from the open API.

    Regards,
    Eric
  • In reply to Eric:

    I return to confirm that with SSPv1.2.1 and a BSP configured for the S7G2-SK board, the command g_can0.open() always returns SSP_ERR_CAN_INIT_FAILED ... I tried clock source CAN MCLK (default) and PCLKB, the result is the same.

    I then redesigned the SSP1.1.0 (still for the S7G2-SK). This time the command open is OK!

    Are you sure the CAN driver is compatible with the SSP v1.2.1? Should SSPv1.1.0 be uninstalled? (I created a new project each time for this test).

    Should the latest SSP v1.3.0 versions be installed?
    My workstation is on Windows Seven 64bits.

    Thank you for your help, it will become urgent for me because a project based on S3 must start next week ...
  • In reply to Eric:

    Hi Eric,

    Could you set Number of mailboxes to 32 and check again?

    Regards,
    adboc
  • In reply to adboc:

    Hi Eric,

    Like abdoc just said, I think the problem lies in this parameter.
    I think i saw that bug when i was playing with the can module. I think everything will be resolved when you return to 32 mailbox. But I don't know why...

    If someone can explain if it's not a bug, that would be great !

    regards,
    Clément.
  • In reply to adboc:

    Hi Adboc,

    yes, if I'm setting Number of mailbox to 32, open is now OK... I set 4 Mailbox for avoid to set all ID :)...

    But, now, I have others problems... Indeed, when I try to read or write in mailboxes I get the errors BUS OFF, (for read) or BUS HEAVY (for write). I checked the hardware but it seems ok.... (This problem is the same with SSP v1.1.0).

    I use a PeakSystem CAN/USB apdaptator connected on J7 of SK-SG7G2.

    Thanks for help.

    Eric
  • In reply to Eric:

    Hi Eric,

    If you would like to configure baud rate to 500 kbps, you should use different values of the prescaler and time segments. CAN MCLK is generated by Main Clock, for SK-S7G2 by default it's 24 MHz (XTAL). Let's say the prescaler value is K. Tq count is the sum of Time segment 1 and Time segment 2 plus 1 for SS:

    Tq count = TSEG1 + TSEG2 + SS (SS = 1 Tq)

    The output baud rate can be calculated using the formula:

    baud rate = fCAN / (K * Tq count)

    Using your settings, the resulting baud rate is:

    24 MHz / (5 * (15 + 4 + 1)) = 24 MHz / 100 = 240 000 bps

    To achive 500 000 bps, you can set prescaler to 6, Time segment 1 to 4 and Time segment 2 to 3.

    More details can be found in S7G2 hardware manual, section 37.4 (please note, that P + 1 from the manual equals to K).

    Regards,
    adboc
  • In reply to adboc:

    Hi Adboc and thaks again for your help.

    I will try to set prescaler and Time segment like you wrote.

    But I don't use CAN MCLK on last trying, but PCLKB (set at 60MHz normaly... according to Generator code, CLK Tab)...
    I think to have an ACK default ... despite having connected a device normally responding to the ID of the transmitted frame.

    I keep you informed.
    Regards,
    Eric
  • In reply to Eric:

    Hello,

    as promised I return to bring back my last tests.
    In fact, my first setup was correct for PCLKB, (at 60MHz). I had not actually seen that CAN MCLK had its source on XTAL ...
    Sorry.

    On the other hand I have the same problem with both configurations, (PCLKB and CAN MCLK for 500KBds), detection of a BUS OFF when receiving a 8 bytes frame: with the following data: 0x00, 0x49, 0x00, 0x50, 0x00, 0x52, 0x00, 0x02.
    If I pass this frame to 4 bytes it is received correctly.
    If I transmit the first frame it is transmitted correctly.

    If I replace the data 0x00 with values 0x55 or 0xAA the frame is well received ...
    Even 0x01 or 0x10 instead of 0 causes a BUS OFF.

    Tolerance problem in reception speeds?

    Thanks again,
    Eric
  • In reply to Eric:

    Hi Eric,

    It's hard to say what is the cause of this error. Have you tried changing Synchronization Jump Width setting?

    Regards,
    adboc
  • In reply to adboc:

    Hi Adboc,

    No I have not tried this yet, but I think the problem comes from there ...

    What bothers me is that I seem to have seen that the S3 documentation recommends not to exceed 1 for SJW.
    I tried to 250KBds and the problem remains.

    I will see on my PEAKSYSTEM dongle to adjust the Times Quanta Registers.
    (Knowing that this frame is well received by our existing devices (based on SH7269 with this same adapter ...)

    Regards,
    Eric
  • In reply to Eric:

    Hi Adboc,

    just this message to tell you that the BUSOFF problem on the reception of the frame came from my PeakSystem interface.
    I did the tests with another Peaksystem module, and it's all OK!

    In summary; the only real problem was that with the SSP v1.2.1 it is mandatory to configure 32 mailboxes ...
    (I will try with the SSPv1.3.0 to see if this problem is solved but I have not seen it in the reases notes).

    Thank you again for your fruitful help.