Internal CAN-BUS

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

Moderator: Benj

Barmaley_GMN
Posts: 44
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 7 times
Been thanked: 3 times
Contact:

Internal CAN-BUS

Postby Barmaley_GMN » Fri Sep 08, 2017 7:22 am

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: 1736
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 443 times
Been thanked: 946 times
Contact:

Re: Internal CAN-BUS

Postby kersing » Fri Sep 08, 2017 8:02 am

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: 44
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Internal CAN-BUS

Postby Barmaley_GMN » Fri Sep 08, 2017 9:04 am

Yat1_v6222222.fcfx
(13.73 KiB) Downloaded 33 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: 1325
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 329 times
Been thanked: 477 times
Contact:

Re: Internal CAN-BUS

Postby LeighM » Sat Sep 09, 2017 8:14 pm

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: 44
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Internal CAN-BUS

Postby Barmaley_GMN » Sat Sep 09, 2017 9:58 pm

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: 44
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Internal CAN-BUS

Postby Barmaley_GMN » Sun Sep 10, 2017 8:42 pm

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.45 KiB) Downloaded 22 times

User avatar
LeighM
Matrix Staff
Posts: 1325
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 329 times
Been thanked: 477 times
Contact:

Re: Internal CAN-BUS

Postby LeighM » Mon Sep 11, 2017 9:53 am

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
These users thanked the author LeighM for the post:
Barmaley_GMN (Mon Sep 11, 2017 8:14 pm)
Rating: 5.88%
 

Barmaley_GMN
Posts: 44
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Internal CAN-BUS

Postby Barmaley_GMN » Mon Sep 11, 2017 2:35 pm

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: 1325
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 329 times
Been thanked: 477 times
Contact:

Re: Internal CAN-BUS

Postby LeighM » Mon Sep 11, 2017 3:32 pm

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

Barmaley_GMN
Posts: 44
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Internal CAN-BUS

Postby Barmaley_GMN » Mon Sep 11, 2017 8:13 pm

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!
These users thanked the author Barmaley_GMN for the post:
LeighM (Tue Sep 12, 2017 8:40 am)
Rating: 5.88%