Page 1 of 2
Problem with CanBus (STM32F407) when alone on bus.
Posted: Mon Feb 01, 2016 10:15 am
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
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Mon Feb 01, 2016 11:33 am
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
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Mon Feb 01, 2016 12:10 pm
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
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Mon Feb 01, 2016 1:46 pm
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
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Mon Feb 01, 2016 2:35 pm
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.
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Mon Feb 01, 2016 4:50 pm
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
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Tue Feb 02, 2016 7:30 am
by jkozien
The test loop is working properly because it still restarting canbus, - (canStop -> canStart -> ... etc. ) without restarting it doesn't work too.
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Tue Feb 02, 2016 7:42 am
by franek.bmw
Jaroslaw, please show us your canbus configuration. I think there is problem.
Best regards,
Franek
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Tue Feb 02, 2016 7:47 am
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)
};
Re: Problem with CanBus (STM32F407) when alone on bus.
Posted: Tue Feb 02, 2016 7:52 am
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.
