Page 1 of 1

Internal CAN-BUS

Posted: Fri Sep 08, 2017 7:22 am
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?

Re: Internal CAN-BUS

Posted: Fri Sep 08, 2017 8:02 am
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.

Re: Internal CAN-BUS

Posted: Fri Sep 08, 2017 9:04 am
by Barmaley_GMN
Yat1_v6222222.fcfx
(13.71 KiB) Downloaded 265 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.

Re: Internal CAN-BUS

Posted: Sat Sep 09, 2017 8:14 pm
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.

Re: Internal CAN-BUS

Posted: Sat Sep 09, 2017 9:58 pm
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.

Re: Internal CAN-BUS

Posted: Sun Sep 10, 2017 8:42 pm
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 220 times

Re: Internal CAN-BUS

Posted: Mon Sep 11, 2017 9:53 am
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

Re: Internal CAN-BUS

Posted: Mon Sep 11, 2017 2:35 pm
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?

Re: Internal CAN-BUS

Posted: Mon Sep 11, 2017 3:32 pm
by LeighM
With FC6 only the four standard speeds are selectable in the component, the config registers are not exposed for modification

Re: Internal CAN-BUS

Posted: Mon Sep 11, 2017 8:13 pm
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!