Hello,
can some one help me? I find only exampels with 4MHZ Quarz with 250kb and i dont understand what i have to change in the Configbits to use a 16MHZ Quarz and 250kb
//initialises CAN communications
void CAN_init(void){
//initialise MSCAN
CAN0CTL0 = 0x01;
while (!(CAN0CTL1_INITAK)){}
CAN0CTL1_CANE = 1; /* Enable MSCAN module */
CAN0CTL1_CLKSRC = 0; /* Clock source is OSCCLK = 20 MHz */
CAN0CTL1_LOOPB = 0; /* Set to 1 for LoopBack Mode, 0 otherwise */
CAN0CTL1_LISTEN = 0; /* Not listen only mode */
CAN0CTL0_WUPE = 1; /* Enable WAKEUP */
//Baud rate = CANCLK/(Pre-scaler * time quanta)
CAN0BTR1_TSEG_10 = 0x0A; // that works with 4MHZ
CAN0BTR1_TSEG_20 = 0x03; // and 250kb
CAN0BTR0_BRP = 0x00; //
CAN0BTR0_SJW = 0x03;
CAN0BTR1_SAMP = 0;
Can some one tell me the right value?
Thanks a lot
Thorsten
已解决! 转到解答。
Hi Thorsten,
You are right, your PLL setting is not correct.
I would like to recommend (for 32MHz bus clock from 16MHz crystal):
CPMUREFDIV_REFFRQ = 0x3; //Reference clock > 12MHz
CPMUREFDIV_REFDIV = 0x0; //FREF=16/(0+1) = 16MHZ
CPMUSYNR_VCOFRQ = 0x1; //FVCO is between 48MHZ and 80MHZ
CPMUSYNR_SYNDIV = 0x1; //FVCO = 2xFREFx(SYNDIV+1) = 2x16x(1+1) = 64MHZ
CPMUPOSTDIV_POSTDIV = 0x0; //FPLL = FVCO/(POSTDIV+1) = 64MHZ/(0+1) = 64MHz. FBUS=FPLL/2 = 32MHz
Since CAN bus runs from external oscillator, I am not sure whether this could be a root cause of this issue.
You should configure also acceptance filter, enter into normal mode and potentially also wait for CAN bus synchronization inside your CAN_init() function.
For example:
…
CAN0BTR0 = 0xC3;
CAN0BTR1 = 0x67;
CANIDMR0 = CANIDMR1 = CANIDMR2 = CANIDMR3 = 0xFF;
CANIDMR4 = CANIDMR5 = CANIDMR6 = CANIDMR7 = 0xFF;
CANCTL0 = 0x00; // restarts MSCAN peripheral
while(CANCTL1 & CANCTL1_INITAK_MASK); // wait for Initialization Mode exit
while(!(CANCTL0 & CANCTL0_SYNCH_MASK)); // waits for MSCAN synchronization with the CAN bus
}
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Thorsten,
Please look at attached CAN baudrate calculator.
Enter your oscillator clock, required CAN speed and Physical Interface Tx+ Rx propagation delay.
Calculator will highlight CANBTR0 and CANBTR1 register values. For example:
16MHz, 250bit/s, 255ns -> CANBTR0 = 0xC3, CANBTR1 = 0x67.
So, you could replace code
CAN0BTR1_TSEG_10 = 0x0A; // that works with 4MHZ
CAN0BTR1_TSEG_20 = 0x03; // and 250kb
CAN0BTR0_BRP = 0x00; //
CAN0BTR0_SJW = 0x03;
CAN0BTR1_SAMP = 0;
By these lines:
CANBTR0 = 0xC3;
CANBTR1 = 0x67;
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi RadekS,
sorry but it dosent works:(
I think i have a Problem witch the PLL settings but wich?
Here my complet Config
//initialises the PLL
void PLL_init(void){
CPMUCLKS_PLLSEL = 1; //FBUS = FPLL/2. FBUS = 32MHz,
CPMUREFDIV_REFFRQ = 3; // Reference clock > 12MHz
CPMUREFDIV_REFDIV = 0x3; //FREF=8/(1+1) = 4MHZ
CPMUSYNR_VCOFRQ = 0x1; //FVCO is between 48MHZ and 80MHZ
CPMUSYNR_SYNDIV = 0x1; //FVCO = 2xFREFx(SYNDIV+1) = FVCO = 2x4x(7+1) = 64MHZ
CPMUPOSTDIV_POSTDIV = 0x0; //FPLL = FVCO/(POSTDIV+1). FPLL = 64MHZ/(0+1) FPLL = 64MHz
CPMUOSC_OSCE = 1; //External oscillator enable. 8MHZ. FREF=FOSC/(REFDIV+1)
while(!CPMUIFLG_LOCK){} // Wait for LOCK.
CPMUIFLG = 0xFF; // clear CMPMU int flags - not needed but good practice
}
//initialises CAN communications
void CAN_init(void){
//initialise MSCAN
CAN0CTL0 = 0x01;
while (!(CAN0CTL1_INITAK)){}
//initialise MSCAN
CAN0CTL0 = 0x01;
while (!(CAN0CTL1_INITAK)){}
CAN0CTL1_CANE = 1; /* Enable MSCAN module */
CAN0CTL1_CLKSRC = 0; /* Clock source is OSCCLK = 16 MHz */
CAN0CTL1_LOOPB = 0; /* Set to 1 for LoopBack Mode, 0 otherwise */
CAN0CTL1_LISTEN = 0; /* Not listen only mode */
CAN0CTL0_WUPE = 1; /* Enable WAKEUP */
CAN0BTR0 = 0xC3;
CAN0BTR1 = 0x67;
in the PLL Area i try some different values,i think thats my problem but i dont anderstand the exampel.me english is not so good
thanks for your help
Hi Thorsten,
You are right, your PLL setting is not correct.
I would like to recommend (for 32MHz bus clock from 16MHz crystal):
CPMUREFDIV_REFFRQ = 0x3; //Reference clock > 12MHz
CPMUREFDIV_REFDIV = 0x0; //FREF=16/(0+1) = 16MHZ
CPMUSYNR_VCOFRQ = 0x1; //FVCO is between 48MHZ and 80MHZ
CPMUSYNR_SYNDIV = 0x1; //FVCO = 2xFREFx(SYNDIV+1) = 2x16x(1+1) = 64MHZ
CPMUPOSTDIV_POSTDIV = 0x0; //FPLL = FVCO/(POSTDIV+1) = 64MHZ/(0+1) = 64MHz. FBUS=FPLL/2 = 32MHz
Since CAN bus runs from external oscillator, I am not sure whether this could be a root cause of this issue.
You should configure also acceptance filter, enter into normal mode and potentially also wait for CAN bus synchronization inside your CAN_init() function.
For example:
…
CAN0BTR0 = 0xC3;
CAN0BTR1 = 0x67;
CANIDMR0 = CANIDMR1 = CANIDMR2 = CANIDMR3 = 0xFF;
CANIDMR4 = CANIDMR5 = CANIDMR6 = CANIDMR7 = 0xFF;
CANCTL0 = 0x00; // restarts MSCAN peripheral
while(CANCTL1 & CANCTL1_INITAK_MASK); // wait for Initialization Mode exit
while(!(CANCTL0 & CANCTL0_SYNCH_MASK)); // waits for MSCAN synchronization with the CAN bus
}
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------