Can Bus baudrate

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

Moderator: Benj

Post Reply
georgp
Posts: 37
Joined: Tue Sep 03, 2013 8:29 am
Has thanked: 8 times
Been thanked: 4 times
Contact:

Can Bus baudrate

Post by georgp »

Hi
I amusing an Arduino Uno board with Microchip Can via spi.
I found that when I set baud to 125 khz my analyser says its 100khz.
Now on J1939 I need 250 khz but I dont get comms.
Is there a way to calibrate this in flowcode other than trial and error to get this correct.
Then it may be fuse bits on the mega328.
Hope somebody can guide me on this because if the can bus speed is critical
Thanks

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Can Bus baudrate

Post by Jan Lichtenbelt »

Hi Georgp


Had to say with so less information. I would look carefully in the frequencies settings of the oscillator used for the microchip.


Kind regards

Jan Lichtenbelt

georgp
Posts: 37
Joined: Tue Sep 03, 2013 8:29 am
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Can Bus baudrate

Post by georgp »

sorry baud was suppose to be 125 kbps comes out as 100kbps and 250 as 200 on the analyser. I a, using a board from mikroelektronika but what I need is to change the baud rate in flowcode. I want to send J1939 It seems to me that in flowcode 5 ther was some control over this but not in flowcode 6.

georgp
Posts: 37
Joined: Tue Sep 03, 2013 8:29 am
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Can Bus baudrate

Post by georgp »

Just some more info on this problem. The board I am using has a 16 MHz xtal and the EBlocks I see use 20 MHz this is also 80% as my buadrates are also 80% of what it should be.
Thanks

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Can Bus baudrate

Post by kersing »

Have you selected the correct speed in the project properties?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Can Bus baudrate

Post by LeighM »

You are correct the CAN component for external MCP2515 assumes a 20MHz xstal
To operate at 16MHz you will need to calculate and change the setup of the CNF1, CNF2 and CNF3 registers of the MCP2515.

CNF1 sets the Baud rate prescaler bits, but you will also need to modify the CNF2 and CNF3 and set the CAN bit timing segment bit lengths so that the total bit time matches your required CAN baud rate.

Then after your call to the CAN Intialise macro, the CNF values can be changed to your new ones by inserting some C code as follows:

Code: Select all

	FC_CAN_SPI_CAN_Config_1(128);  // into CONFIG mode
	FC_CAN_SPI_CAN_Write_1(42, 7 /* replace with your CNF1 value */); 
	FC_CAN_SPI_CAN_Write_1(41, 209 /* replace with your CNF2 value */);
	FC_CAN_SPI_CAN_Write_1(40, 3 /* replace with your CNF3 value */);
	FC_CAN_SPI_CAN_Config_1(0);   // into NORMAL mode
Hope that helps
Leigh

georgp
Posts: 37
Joined: Tue Sep 03, 2013 8:29 am
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Can Bus baudrate

Post by georgp »

Wow thanks a lot I will try

georgp
Posts: 37
Joined: Tue Sep 03, 2013 8:29 am
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Can Bus baudrate

Post by georgp »

Hi Leigh
Thanks this worked for me thanks. Now a second problem maybe you can help with this. I have a 4dsystems display and I wan to use a winbutton to send various bytes to an ID.
The problem I have is after the first byte the CAN keeps on sending and never stops. I tried connecting reset to an output but cant get it to start up again.
On the fly putting variable in D0 seems to be ignored . Then I have chip enable no luck either.
All I want is to send typically the button nr like 1,2,3,4,5,6 to an ID say 00FEE900 when a buttons is pressed.
I use settxdata then send buffer. It works fine only for the first button.
Thanks
Georg

Post Reply