 ARM: CAN1 baud rate setting Demis Biscaro I have some problems with configuration of CAN1 baud rate setting in LPC2378. This is the code section that configure CAN1 controller. Mind that CPU clock frequency CLK is 72 MHz .
void start_an_network(unsigned long can_btr){
unsigned long dummy;
// CAN controller 1
dummy = CAN1ICR; // reset interrupt flag
CAN1MOD |= 1; // reset can controller
// Set peripheral clock
PCLKSEL0 &= ~(3 << 26); // CLK / 4 = 72/4 = 18 MHz
// PCLKSEL0 |= (1 << 26); // CLK / 1 = 72/1 = 72 MHz
// PCLKSEL0 |= (2 << 26); // CLK / 2 = 72/2 = 36 MHz
// Enable clock to the peripheral
PCONP |= PCAN1;
// port configuration
PINSEL0 &= ~0x00000F0F;
PINSEL0 |= 0x0000005;
CAN1IER = 0; // Disable Receive Interrupt
CAN1GSR = 0; // Reset error counter
CAN1BTR = can_btr; // baud rate setting
CAN_AFMR = 0x02; // by pass mode
CAN1MOD = 0x0; // CAN in normal operation mode
// irq configuration follows...
}
If I configure peripheral clock frequency to 72/4 MHz, messages are transmitted and received correctly. However I cannot configure CAN controller baud rate to 800 kbit/s because of time quantization. Therefore I have tried to set peripheral clock frequency to 72 MHz and then to set baud rate to 1000 kbit/s using can_btr = 0x00270005 or can_btr = 0x003C0003 In this case I've seen through debugger that after the execution of the instruction
CAN1BTR = can_btr;
the value into CAN1BTR register is always 0! After that I've tried to set peripheral clock frequency to 72/2 MHz and CAN baud rate to 1000 kbit/s using can_btr = 0x00270002 or can_btr = 0x003C0001 In this case I've seen that the value is correctly written into CAN1BTR register, however messages emitted by CAN controller are not correct (I've controlled them with a CAN analyzer and with an oscilloscope). Have you ever seen such troubles like these ones? Have you ever any suggestion? Thank you, Demis |