stm32F7xx + bxCAN + Peak (PCANview) communication issue (Keil v5)
- April 29, 2019
- 5 replies
- 2784 views
Hello ST community!
For some time now I've been trying to make the CANbus work and in the end I did but unfortunately only to some extend. Using 2 CAN SN65HVD230 modules, STM32F746IGT6 core, waveshare Open7XXI-C main board I managed to run slightly modified example file from https://www.waveshare.com/wiki/File:Open746I-C-Demo-HAL.7z (11.CAN). Until now everything's good, modules communicate with each other. The problem occurs when I try to transmit or receive some CAN data using PCANview with PEAK tool.
Now considering my target baudrate which is 500kb/s I've changed few can init settings based on http://www.bittiming.can-wiki.info website:
Clock Rate: 216 Mhz*,
Sample point: 87.5%,
SJW: 1,
kbit/s: 500,
* the 216 Mhz comes from HAL_PWREx_ActivateOverDrive(), which sets the clock to 216 Mhz.
resulting in:
Prescaler: 27,
Segment 1 time quanta: 13,
Segment 2 time quanta: 2.
Considering the above, this is how the code looks in can.c (CAN2 init is identical)
void MX_CAN1_Init(void){
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 27;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SJW = CAN_SJW_1TQ;
hcan1.Init.BS1 = CAN_BS1_13TQ;
hcan1.Init.BS2 = CAN_BS2_2TQ;
hcan1.Init.TTCM = DISABLE;
hcan1.Init.ABOM = DISABLE;
hcan1.Init.AWUM = DISABLE;
hcan1.Init.NART = DISABLE;
hcan1.Init.RFLM = DISABLE;
hcan1.Init.TXFP = DISABLE;
HAL_CAN_Init(&hcan1);
}The CAN1 filter is configured in the following code (no filter):
sFilterConfig.FilterNumber = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 14;
HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig);When configuration is done as above and PCANview set to 500kbit/s the status instantly goes to BUSHEAVY and when I try to send some message I get BUS-OFF but the modules still communicate with each other, just not with the PEAK.
I'm 99% sure that I checked if the peripherals I use may have some influence and it's very unlikely. Both transceivers work. I have only two terminals, one per used transceiver.
I was already trying different time quanta settings, prescaler, PEAK baudrates and more with no result. Perhaps I'm just forgetting about something and the solution is very easy. Anyway, I'm attaching main.c code, and I know it's quite messy, but I'm in an early stage of development and still learning.
To be honest I recently moved from Arduino (mostly because of multiple peripherals malfunctions or conflicts resulting in attaching more arduinos to the same project) to STM and I'm in the middle of trying to move the code to the new platform, too.
Any help would be greatly appreciated, thank you!
