AnsweredAssumed Answered

CAN speed change in main

Question asked by Thorsten Mumm on Aug 20, 2018
Latest reply on Aug 28, 2018 by Thorsten Mumm

Hello all,

 

how can i change the speed of a CAN-Bus in Main depend of a selection before

I try this but it dosent works

if(CAN_Typ == MCAN)
  {
      /* CAN0CTL1: CANE=1,CLKSRC=0,LOOPB=0,LISTEN=0,BORM=0,WUPM=0,SLPAK=0,INITAK=0 */
      setReg8(CAN0CTL1, 0x80U);            /* Set the control register */
      /* CAN0CTL0: RXFRM=0,RXACT=0,CSWAI=0,SYNCH=0,TIME=0,WUPE=0,SLPRQ=0,INITRQ=1 */
      setReg8(CAN0CTL0, 0x01U);            /* Set the control register */
      
      
      /* CAN0BTR0: SJW1=1,SJW0=1,BRP5=0,BRP4=0,BRP3=0,BRP2=1,BRP1=1,BRP0=1 */
        CAN0BTR0 = 0xC7U;                    // for 250k    /* Set the device timing register */
        
        CAN0CTL0_INITRQ = 0x00U;             /* Start device */
        while(CAN0CTL1_INITAK) {}            /* Wait for enable */
        /* CAN0RFLG: WUPIF=1,CSCIF=1,RSTAT1=1,RSTAT0=1,TSTAT1=1,TSTAT0=1,OVRIF=1 */
        CAN0RFLG |= 0xFEU;                   /* Reset error flags */
        /* CAN0RIER: WUPIE=0,CSCIE=1,RSTATE1=1,RSTATE0=1,TSTATE1=1,TSTATE0=1,OVRIE=0,RXFIE=1 */
        CAN0RIER = 0x7DU;                    /* Enable interrupts */      
  }
  else
  {
      /* CAN0CTL1: CANE=1,CLKSRC=0,LOOPB=0,LISTEN=0,BORM=0,WUPM=0,SLPAK=0,INITAK=0 */
        setReg8(CAN0CTL1, 0x80U);            /* Set the control register */
        /* CAN0CTL0: RXFRM=0,RXACT=0,CSWAI=0,SYNCH=0,TIME=0,WUPE=0,SLPRQ=0,INITRQ=1 */
        setReg8(CAN0CTL0, 0x01U);            /* Set the control register */         
    
          CAN0BTR0 = 0xCFU;                    // for 125k     /* Set the device timing register */

 

        CAN0CTL0_INITRQ = 0x00U;             /* Start device */
        while(CAN0CTL1_INITAK) {}            /* Wait for enable */
        /* CAN0RFLG: WUPIF=1,CSCIF=1,RSTAT1=1,RSTAT0=1,TSTAT1=1,TSTAT0=1,OVRIF=1 */
        CAN0RFLG |= 0xFEU;                   /* Reset error flags */
        /* CAN0RIER: WUPIE=0,CSCIE=1,RSTATE1=1,RSTATE0=1,TSTATE1=1,TSTATE0=1,OVRIE=0,RXFIE=1 */
        CAN0RIER = 0x7DU;                    /* Enable interrupts */
  }     

 

when i change the speed in hardware of codeworier it works with 125k or 250k

and only the line CAN0BTR0 = 0xCFU is difrent

how can help?

 

thanks thorsten

Outcomes