Problem with CanBus (STM32F407) when alone on bus.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

jkozien
Posts: 6
Joined: Fri Jan 29, 2016 12:48 pm

Problem with CanBus (STM32F407) when alone on bus.

Post by jkozien »

Hello ,
I have a problem with CanBus operation in STM32F407 when my device is alone on bus then stops transmition and reception.
I must start other device first on bus - which transmit or receive frames and then switch on (or reset) my device with STM32F407 (ChibiOS) .
Then everything works.
My device can not first begin to send and receive because then stops working even then when other devices after several seconds (for example 15 seconds) starts correctly work on CanBus (then after reset STM32F407 my device starts working also(receive and transmit)).

Jaroslaw
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by Giovanni »

Hi,

I am not sure about what the problem could be here. Could it be related to HW (drivers, wiring, terminations etc)?

Giovanni
jkozien
Posts: 6
Joined: Fri Jan 29, 2016 12:48 pm

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by jkozien »

Thank you for replay.
I'm sure that hardware is ok.
I wrote a piece of code that sends a message and control descriptor fd.

Code: Select all

      fd = canTransmit(&CAND1, 0, &CanFrameTX, MS2ST(10));
      if (fd < 0)
      {
         chprintf((BaseSequentialStream *)&SD2, "Transmit fail \r\n");
         canStop(&CAND1);      //still restarting can until fd >=0
         canStart(&CAND1, &CurrentCanBusConfig);
      }

When I add other device on canbus then fd = 0 and my device (after restarting Can) start working properly.

Jaroslaw
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by Giovanni »

Try adding a delay before canStop(), it is possible that the clock is stopped while the unit is still trying to transmit.

Giovanni
jkozien
Posts: 6
Joined: Fri Jan 29, 2016 12:48 pm

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by jkozien »

It's no problem in this piece of code - this code is only a test loop , which detect the moment when I insert another transmitting/receiving device on CanBus. It's work (test loop) properly and correctly switch the CanBus on in my STM32F407 device. But if I only initialize CanBus in my STM32F407 device on startup (canStop()canStart()) then if my device is first on the bus - the CanBus driver never startup.

Normally this test loop doesn't exist in my code .
Test loop:

Code: Select all

   while(true)
   {
      chThdSleepMilliseconds(1000);

      fd = canTransmit(&CAND1, 0, &CanFrameTX, MS2ST(10));
      if (fd < 0)
      {
         chprintf((BaseSequentialStream *)&SD2, "Transmit fail \r\n");
         chThdSleepMilliseconds(100);
         canStop(&CAND1);
         canStart(&CAND1, &CurrentCanBusConfig);
      }
   }


If my device is connected to the bus while others are already working then there is no problem - my test loop is then not required.
It seems to me that the startup procedure does not work or the driver switches off when there is no incoming frames or no device receives frames.

One-time initialization code(startup procedure):

Code: Select all

   
         chThdYield();
   canStop(&CAND1);
   canStart(&CAND1, config);

It is only once initialized at the start of the program.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by Giovanni »

The test application works even if there are no other devices transmitting. What is different in your case? could you try to set the loopback mode and see if the behavior is the same?

Giovanni
jkozien
Posts: 6
Joined: Fri Jan 29, 2016 12:48 pm

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by jkozien »

The test loop is working properly because it still restarting canbus, - (canStop -> canStart -> ... etc. ) without restarting it doesn't work too.
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by franek.bmw »

Jaroslaw, please show us your canbus configuration. I think there is problem.

Best regards,
Franek
jkozien
Posts: 6
Joined: Fri Jan 29, 2016 12:48 pm

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by jkozien »

My CanBus configuration:

Code: Select all

           const CANConfig cancfg_500k = {
      CAN_MCR_TXFP ,
      CAN_BTR_SJW(0) | CAN_BTR_TS2(2) |
      CAN_BTR_TS1(9) | CAN_BTR_BRP(5)
};
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: Problem with CanBus (STM32F407) when alone on bus.

Post by franek.bmw »

You must set bit ABOM, this solves your problem.
Your configuration should look like this:

Code: Select all

           const CANConfig cancfg_500k = {
      CAN_MCR_TXFP | CAN_MCR_ABOM ,
      CAN_BTR_SJW(0) | CAN_BTR_TS2(2) |
      CAN_BTR_TS1(9) | CAN_BTR_BRP(5)
};



Let me know if this helps. :)
Post Reply