Skip to main content
Associate III
March 18, 2015
Question

STM32F407 and LPC1788 ''CAN'' connection

  • March 18, 2015
  • 1 reply
  • 541 views
Posted on March 18, 2015 at 11:42

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.
    This topic has been closed for replies.

    1 reply

    Associate III
    March 23, 2015
    Posted on March 23, 2015 at 11:46

    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.