Internal CAN-BUS

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

Moderator: Benj

Post Reply
Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Internal CAN-BUS

Post by Barmaley_GMN »

I have a problem; internal CAN-BUS doesn't work well.
I have a project with PIC 18F2580 it works with crystal 16MHz.
When I try to send any packet it seems like wrong boud rate (I don't know exactly) and I don't see the packet.
But external CAN-BUS with MCP2515 on 20MHz works good.
How can I solve problem with internal CAN-BUS?

And one more: do both CAN-BUS (internal and external as two components) work together?

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: Internal CAN-BUS

Post by kersing »

Please attach a flowchart file (not screen shots) with problems so settings of the controller and components can be verified in case that might be an issue.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Internal CAN-BUS

Post by Barmaley_GMN »

Yat1_v6222222.fcfx
(13.71 KiB) Downloaded 262 times
It is

As I see, FC6 makes the same code for diffident crystals (16 and 20 MHz):

Code: Select all

//setup CNF and control registers

    FC_CAN_SPI_CAN_Config_2(FCV_0e702_can2__CAN_REQOP_CONFIG);
    FC_CAN_SPI_CAN_Write_2(FCV_0e702_can2__CAN_CNF1, 1);
    FC_CAN_SPI_CAN_Write_2(FCV_0e702_can2__CAN_CNF2, 209);
    FC_CAN_SPI_CAN_Write_2(FCV_0e702_can2__CAN_CNF3, 3);

//setup CNF and control registers

    FC_CAN_SPI_CAN_Config_1(FCV_0e701_can1__CAN_REQOP_CONFIG);
    FC_CAN_SPI_CAN_Write_1(FCV_0e701_can1__CAN_CNF1, 1);
    FC_CAN_SPI_CAN_Write_1(FCV_0e701_can1__CAN_CNF2, 209);
    FC_CAN_SPI_CAN_Write_1(FCV_0e701_can1__CAN_CNF3, 3);
And it should be diffident.

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: Internal CAN-BUS

Post by LeighM »

Hi, I cannot check the Flowcode file just now, but just a comment on the C code...
That looks like the external CAN code, where the crystal freq is set in the External CAN component.
You will need to look for other similarly named defines in the C code for the internal CAN.
I'll be better able to help on Monday.

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Internal CAN-BUS

Post by Barmaley_GMN »

Thanks!
I have checked with only one internal channel - it doesn't work on my project. Something is going from MCP2551 but I can't catch any pocket/ I'd tried standard (100,125,500) and another (95,238) boudrate.
And the same flowchat from FC5 - works fine.

When I changed crystal for PIC from 16 to 20 MHz and rebuilt the project (with this changes) it stared work with 2 CAN interfaces.

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Internal CAN-BUS

Post by Barmaley_GMN »

And a new problem:
How can I change boudrate for internal can on this flowchat?
At this case it still sends packets on 125kbps. If I change boudrate to 500kbps by standard form (without removing C-form) - I can't catch any packets on 500,125, 95.238 kbps.

p.s. External CAN-BUS sends packets on 95.238 kbps (as I need).
Yat1_v63333.fcfx
(16.43 KiB) Downloaded 217 times

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: Internal CAN-BUS

Post by LeighM »

Hi,
To customize the internal CAN baud rate you will need to do something like this ...

Code: Select all

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

// change the baud rate registers
brgcon3 = 3;
brgcon2 = 209;
brgcon1 = 1;

// Request normal mode.
cancon = MX_CAN_REQOP_NORMAL;
while( (canstat & MX_CAN_OP_MODE_BITS) != MX_CAN_REQOP_NORMAL );
Hope that helps,
Leigh

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Internal CAN-BUS

Post by Barmaley_GMN »

Thanks!
I will check it.
Is it only one way to sen baud rate through additional С code, or FC6 has another options as it was in FC5?

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: Internal CAN-BUS

Post by LeighM »

With FC6 only the four standard speeds are selectable in the component, the config registers are not exposed for modification

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Internal CAN-BUS

Post by Barmaley_GMN »

LeighM wrote:With FC6 only the four standard speeds are selectable in the component, the config registers are not exposed for modification
it's sad. It is step to uncomfortable using the FC.
And thanks again, your code works fine!

Post Reply