2015-03-18 03:42 AM
I want to connect STM32f407 CAN to LPC1788 CAN.
I set baudrate to 125000 in STM32 with this spec:prtCan.Init.SJW = CAN_SJW_1TQ;
prtCan.Init.BS1 = CAN_BS1_13TQ;
prtCan.Init.BS2 = CAN_BS2_2TQ;
prtCan.Init.Prescaler = 21;
and in LPC1788:
//Descriptions: CANx->BTR=(TSEG2<<
20
)|(TSEG1<<16)|(SJW<<14)|BRP
CANx->BTR=(1<<20)|(12<<16)|(0<<14)|29;
CAN clock in stm32 is 42MHz and in LPC is 60MHz.
I set both clock to 2MHz with prescale 21 and
I can not communicate between these cores,I send a data [DLC=8] with STM32 to LPC and there is no receive on it and stm32 execution,stop in this line (for internal loop):
HAL_CAN_Transmit(&prtCan,5);
Is my configuration true?
Thanks.
2015-03-23 03:46 AM
I calculate GCD between 60MHz and 42MHz. 6MHz is best clock.
Corrected code with 500Kb/S and 75% sample point: STM32F407:extCan.Init.SJW = CAN_SJW_1TQ;
extCan.Init.BS1 = CAN_BS1_8TQ;
extCan.Init.BS2 = CAN_BS2_3TQ;
extCan.Init.Prescaler = 7;
I wrote a function for LPC1788 to config times(changed from official function:can_SetBaudrate (LPC_CAN_TypeDef *CANx, uint32_t baudrate) ) :
void can_SetTiming(LPC_CAN_TypeDef *CANx,uint8_t SJW,uint8_t TSEG1, uint8_t TSEG2,uint32_t BRP)
{
SJW--;
TSEG1--;
TSEG2--;
BRP--;
/* Enter reset mode */
CANx->MOD = 0x01;
/* Set bit timing */
CANx->BTR = (TSEG2 <<
20
) | (TSEG1 << 16) | (SJW << 14) | BRP;
/* Return to normal operating */
CANx->MOD = 0;
}
and then:
can_SetTiming(pCan,1,8,3,10);
Problem is solved now.