[SOLVED] CANBUS Issues.
Posted: Sat Nov 14, 2015 4:10 am
Hi All,
I am attempting to connect to my vehicles can bus using a STM32F103RET6 via a MCP2551. I have a DSO attached to RX on the MCP2551 and I can verify that I am getting nice clean data from the ECU (See attached DSO screenshot), and I have verified that the RX bit is flipping on the CAN status register, but I never seem to get any data. I believe the issue is a baud rate calculation problem. I have verified on the DSO that the baud is 500kbps (shortest bit is 2us), and this agrees with public information on the car.
Here is my CANConfig struct.
The MCU is on a 8MHz HSE, 72MHz Clock, with a divisor of 2 on the perhiperal bus, so the clock is 36MHz.
From what I understand, the baud rate can be calculated like so:
So using the above values:
I am remapping the CAN1 to PB8 & 9 using the following code
If anyone could provide any help on this it would be greatly appreciated.
CH1 = Output of transciever
CH2 = High Line
I am attempting to connect to my vehicles can bus using a STM32F103RET6 via a MCP2551. I have a DSO attached to RX on the MCP2551 and I can verify that I am getting nice clean data from the ECU (See attached DSO screenshot), and I have verified that the RX bit is flipping on the CAN status register, but I never seem to get any data. I believe the issue is a baud rate calculation problem. I have verified on the DSO that the baud is 500kbps (shortest bit is 2us), and this agrees with public information on the car.
Here is my CANConfig struct.
Code: Select all
static const CANConfig cancfg = {
.mcr = CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
.btr = CAN_BTR_BRP(4) | CAN_BTR_SJW(1) | CAN_BTR_TS1(12) | CAN_BTR_TS2(5) | CAN_BTR_SILM
};
The MCU is on a 8MHz HSE, 72MHz Clock, with a divisor of 2 on the perhiperal bus, so the clock is 36MHz.
From what I understand, the baud rate can be calculated like so:
Code: Select all
STM32_PCLK1 / (BRP * (SJW + TS1 + TS2) = bpsSo using the above values:
Code: Select all
36,000,000 / (4 * (1 + 12 + 5) = 500,000I am remapping the CAN1 to PB8 & 9 using the following code
Code: Select all
/* configure CAN */
AFIO->MAPR |= AFIO_MAPR_CAN_REMAP_REMAP2; /* Remap CAN to PB8 (RX) & PB9 (TX) */
palSetPadMode(GPIOB, 8, PAL_MODE_INPUT); /* set PB8 to input PP */
palSetPadMode(GPIOB, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL); /* set PB9 to output alt PP */
canSTM32SetFilters(0, 0, NULL); /* dont filter anything */
canStart(&CAND1, &cancfg); /* start the pheriperal */
chThdCreateStatic(can_rx_wa, sizeof(can_rx_wa), NORMALPRIO + 7, can_rx, NULL);
If anyone could provide any help on this it would be greatly appreciated.
CH1 = Output of transciever
CH2 = High Line