CAN BAUD RATE

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

msahin1976
Posts: 18
Joined: Tue Aug 23, 2016 8:03 am
Has thanked: 3 times
Been thanked: 2 times
Contact:

CAN BAUD RATE

Postby msahin1976 » Wed Sep 26, 2018 8:47 am

Hello,
I need to set can bus baud rate to 50kbps. I tried to do by writing C code, but nothing happened. Can anyone tell me how to do it?

User avatar
Benj
Matrix Staff
Posts: 14313
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4405 times
Been thanked: 4128 times
Contact:

Re: CAN BAUD RATE

Postby Benj » Wed Sep 26, 2018 5:11 pm

Hello,

I believe for 50kbps you need the following Baud settings.

CAN_BAUD1 = 49
CAN_BAUD2 = 218
CAN_BAUD3 = 5
These users thanked the author Benj for the post:
msahin1976 (Thu Sep 27, 2018 7:26 am)
Rating: 5.26%
 

msahin1976
Posts: 18
Joined: Tue Aug 23, 2016 8:03 am
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: CAN BAUD RATE

Postby msahin1976 » Thu Sep 27, 2018 7:26 am

Dear Benj,
Thank you for your answer.
I tried to change "BRGCON" register to set baud rate. The oscillator is 20 MHz. According to this clock, I set the register. The problem was writing to this register directly doesn't work. Later I found another subject CAN baud rate, and I changed the C code like below. Now baud rate is about 50Kbps. Sorry to disturb you. :oops:

// Request config mode.
cancon = MX_CAN_REQOP_CONFIG;
while( (canstat & MX_CAN_OP_MODE_BITS) != MX_CAN_REQOP_CONFIG );

// change the baud rate registers
brgcon1 =0b11001100;
brgcon2 =0b11101001;
brgcon3 =0b00000101;

// Request normal mode.
cancon = MX_CAN_REQOP_NORMAL;
while( (canstat & MX_CAN_OP_MODE_BITS) != MX_CAN_REQOP_NORMAL );