Hello,
I am trying to get the can bus running in both directions (TX and RX) on stm32f103rb and stm32f303re nucleo 64 boards. I have got things running in one direction including CAN filters, but only in the loopback mode, i.e. if BRT_LBKM is set. The same results were achieved with the examples given in testhal, where in a first trial I modified the board.h file for the f103 nucleo board according to the provided Olimex example. In a second trial I used the original board-files but was setting the ports as follows:
static const CANConfig cancfg = {
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
// CAN_BTR_LBKM |
CAN_BTR_SJW(0) | CAN_BTR_TS2(1) |
CAN_BTR_TS1(4) | CAN_BTR_BRP(17)
};
and for the
halInit();
chSysInit();
palSetPadMode (GPIOB, 8, PAL_MODE_INPUT);
palSetPadMode (GPIOA, 9, PAL_MODE_OUTPUT_PUSHPULL);
AFIO->MAPR |= AFIO_MAPR_CAN_REMAP_REMAP2; //CAN PB8/PB9
canStart(&CAND1, &cancfg);
for the strm32f103 board and
palSetPadMode (GPIOA, 11, PAL_MODE_INPUT);
palSetPadMode (GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); // order matters, alternate(9) 2nd
palSetPadMode (GPIOA, 12, PAL_MODE_ALTERNATE(9)); // f303re
for the stm32f303re.
According to a first advise from Giovanni I defined the output pin for the f303 as
palSetPadMode(GPIOA, 12, (PAL_STM32_MODE_ALTERNATE | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_ALTERNATE(9))),
without any effect, since palSetPadMode (GPIOA, 12, PAL_MODE_ALTERNATE(9)) was already sufficient to get a can signal in loopback mode: In case of not properly set outputs I should not have been able to receive any messages by a second f103 on the can bus. The problem seems to be related to the setup of LBKM:
If LBKM is set, the LED blinks and a signal can be measured at the TX pins. If LBKM is not set,
in case of the f103 the messages are send with very short delays between the messages at PA12, i.e. 0.1 ms instead of the required 100ms. If PB9 is used, some short periodic pulse sequences can be seen, but no CAN signal. In case of the f303 no output can be observed without setting LBKM.
Since I am anything else but an embedded computer expert, I would be highly thankful, if anyone could modify the basic testhal-examples (basic nucleo 64 boards or the blue pill) for running TX and RX simultaneously out of the box.
Thanks for help
Hartmut, j10
STM32f103 / f303 CAN TX works only in loopback mode Topic is solved
Moderators: RoccoMarco, barthess
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: STM32f103 / f303 CAN TX works only in loopback mode
Hi,
Do you have a CAN driver attached to the CAN pins? termination resistors? you problem could be electric.
Note that the loopback mode is "internal", there is no need for drivers or other external circuitry.
Giovanni
Do you have a CAN driver attached to the CAN pins? termination resistors? you problem could be electric.
Note that the loopback mode is "internal", there is no need for drivers or other external circuitry.
Giovanni
Re: STM32f103 / f303 CAN TX works only in loopback mode
Hi Giovanni,
I got a CAN-network including filters running based on the MCP2551 with f103/f03 boards, both ends terminated. But as mentioned, only in one direction, i.e. one computer is transmitting signals in loopback mode and the other is receiving messages with loopback mode disabled. So the problem is on the loopback-TX side. I analyzed the CAN bus traffic as well as the I/O ports directly with a Saleae logic analyzer. The transmitted CAN-messages have been recognized by the receiver and analyzer correctly. Furthermore I replaced the TX-f103 with a nucleo64 f303 board without success. So there seem to be no electrical problems.
Hartmut
I got a CAN-network including filters running based on the MCP2551 with f103/f03 boards, both ends terminated. But as mentioned, only in one direction, i.e. one computer is transmitting signals in loopback mode and the other is receiving messages with loopback mode disabled. So the problem is on the loopback-TX side. I analyzed the CAN bus traffic as well as the I/O ports directly with a Saleae logic analyzer. The transmitted CAN-messages have been recognized by the receiver and analyzer correctly. Furthermore I replaced the TX-f103 with a nucleo64 f303 board without success. So there seem to be no electrical problems.
Hartmut
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: STM32f103 / f303 CAN TX works only in loopback mode
Hi,
Is it possible that the f103 and f303 are operating at different speeds?
In addition, I think both CAN RX and TX should be alternate on the f303 (not input for RX), see the alternate table on the datasheet.
Giovanni
Is it possible that the f103 and f303 are operating at different speeds?
In addition, I think both CAN RX and TX should be alternate on the f303 (not input for RX), see the alternate table on the datasheet.
Giovanni
Re: STM32f103 / f303 CAN TX works only in loopback mode
Hi Giovanni,
in case of different speeds (250k bits/s) I would not have received readable messages, the same applies to the analyzer. I checked only the TX channel of the F303 (F103 = RX). F103 = TX and F303 = RX requires as you mentioned setting the RX pin in alternate mode for the F303, too. But than the results become even more confusing: I could receive messages from the F103 only if the TX-thread for the F303 had been disabled ...
But the common problem of both mcu's is related to the fact that both are not transmitting data with disabled LBKM. And this is totally independent of the facts, if a network driver is connected or not and of the speed settings. There seems to be a more fundamental problem with the setup. Since in all CAN examples given in testhal LBKM is not disabled, I would kindly ask you to check the code. Preferably an working example for the little bit more complex F303 would be very helpful.
With best regards and thank you for the help
Hartmut
in case of different speeds (250k bits/s) I would not have received readable messages, the same applies to the analyzer. I checked only the TX channel of the F303 (F103 = RX). F103 = TX and F303 = RX requires as you mentioned setting the RX pin in alternate mode for the F303, too. But than the results become even more confusing: I could receive messages from the F103 only if the TX-thread for the F303 had been disabled ...
But the common problem of both mcu's is related to the fact that both are not transmitting data with disabled LBKM. And this is totally independent of the facts, if a network driver is connected or not and of the speed settings. There seems to be a more fundamental problem with the setup. Since in all CAN examples given in testhal LBKM is not disabled, I would kindly ask you to check the code. Preferably an working example for the little bit more complex F303 would be very helpful.
With best regards and thank you for the help
Hartmut
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: STM32f103 / f303 CAN TX works only in loopback mode
I don't have boards with drivers nor an analyzer for tests, this is why demos are in loopback, for SW testing.
Could you try simplifying the problem? make one board only transmit, the other only receive, then do the opposite. Remove anything is not strictly needed.
Giovanni
Could you try simplifying the problem? make one board only transmit, the other only receive, then do the opposite. Remove anything is not strictly needed.
Giovanni
Who is online
Users browsing this forum: No registered users and 50 guests