mbed library sources
Dependents:
Encrypted
my_mbed
lklk
CyaSSL_DTLS_Cellular
... more
3 comments:
Hello,
is this how you proposed to fix it?
int can_frequency(can_t *obj, int f) {
int btr = can_speed(SystemCoreClock, (unsigned int)f, 1);
int clkdiv = (btr >> 16) & 0x0F;
btr = btr & 0xFFFF;
if (btr > 0) {
uint32_t cntl_init = LPC_CAN->CNTL & CANCNTL_INIT;
// Set the bit clock
LPC_CAN->CNTL |= CANCNTL_CCE | CANCNTL_INIT;
LPC_CAN->CLKDIV = clkdiv;
LPC_CAN->BT = btr;
LPC_CAN->BRPE = 0x0000;
LPC_CAN->CNTL &= ~(CANCNTL_CCE & CANCNTL_INIT);
LPC_CAN->CNTL |= cntl_init << 0;
return 1;
}
return 0;
}
Hi Martin,
On line 13, the statement
LPC_CAN->CNTL &= ~(CANCNTL_CCE & CANCNTL_INIT);
Will actually do nothing, since (CANCNTL_CCE & CANCNTL_INIT) evaluates to 0, and taking the bitwise inverse of that results in 0xFFFFFFFF, which does nothing when anded with the register.
Instead, it should be
LPC_CAN->CNTL &= ~(CANCNTL_CCE | CANCNTL_INIT);
Other than that, your proposed code has the right logic.
On line 14, the bitshift by 0 seems unnecessary, but doesn't affect the correctness.
Thanks for an answer, going to fix it and close this issue.
I placed there logical and by mistake :)
Hello,
is this how you proposed to fix it?