CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18f4550 CAN bus (SOLVED)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
705150



Joined: 25 Apr 2013
Posts: 14

View user's profile Send private message

18f4550 CAN bus (SOLVED)
PostPosted: Mon May 11, 2015 10:47 am     Reply with quote

hi there, i'm working on a project. I have 4 pics connected in CAN bus (3 x 18f25k80 and 18f46k80) with mcp2551.
I want to be able to read what those pics are talking in CAN bus with my laptop. I have an 18f4550 to create a USB to Serial port on laptop, but i also need to connect the 18f4550 to the CAN bus.

Now, the question is: can i simulate a CAN controller (software CAN bus) on a 18f4550 so i can read/write on CAN bus?

my compiler is 5.008

thank you in advance


    Last edited by 705150 on Tue May 12, 2015 9:58 pm; edited 1 time in total
    Ttelmah



    Joined: 11 Mar 2010
    Posts: 19499

    View user's profile Send private message

    PostPosted: Mon May 11, 2015 11:14 am     Reply with quote

    Remember you are going to need an IC to generate the required signals. Canbus uses differential signalling, not simple logic levels. Software Can, is not going to work without this conversion, and the timings would prevent a chip from doing anything else (something like a USB interrupt would destroy the timings). So, simplest solution is to use an IC that does both. Something like the MCP2515. Driver for this (or it's older brother the 2510), is in the drivers directory (can-mcp251x).
    705150



    Joined: 25 Apr 2013
    Posts: 14

    View user's profile Send private message

    PostPosted: Mon May 11, 2015 11:25 am     Reply with quote

    Of course CAN bus can not be driven directly, i am using mcp2551 for that task. However, mcp2551 delivers logic 5v signals at its exits (Rx Tx) and differentials at its inputs (CanL CanH). I was referring from the 2551 side to the 18f4550, if i can simulate a CAN bus driver.
    Ttelmah



    Joined: 11 Mar 2010
    Posts: 19499

    View user's profile Send private message

    PostPosted: Mon May 11, 2015 2:23 pm     Reply with quote

    The driver has to do so much work. I'd say it might be doable, but the chip would end up having to do _nothing_ else. You have very tight timing requirements (which means nothing else interrupting), and then you would need code to do the scanning for conditions etc.. Realistically your PIC would end up not being useful for anything else.
    You'd need to implement the complete state machine, and CRC, together with error handling etc.. At a very low Can rate, it might just about be possible, but will fill most of the PIC's memory, and at higher rates it just won't be able to cope.
    Given the cost of the can interface chip, and that this includes the interface as well, it's silly to not use it.
    705150



    Joined: 25 Apr 2013
    Posts: 14

    View user's profile Send private message

    PostPosted: Mon May 11, 2015 4:15 pm     Reply with quote

    I have these chips lying around the house. I wanted to minimize the number of components, but i guess i will have to use both the 18f4550 for usb to serial and 18f25k80 for the CAN with mcp2551. Thank you for your reply, have a nice day.
    Ttelmah



    Joined: 11 Mar 2010
    Posts: 19499

    View user's profile Send private message

    PostPosted: Tue May 12, 2015 1:35 am     Reply with quote

    You are then adding another chip. Just use the 8550, and the MCP2551. You don't need another PIC.
    RF_Developer



    Joined: 07 Feb 2011
    Posts: 839

    View user's profile Send private message

    Re: 18f4550 CAN bus
    PostPosted: Tue May 12, 2015 3:07 am     Reply with quote

    705150 wrote:

    Now, the question is: can i simulate a CAN controller (software CAN bus) on a 18f4550 so i can read/write on CAN bus?


    The simple answer is no. You need CAN hardware of some sort. The 4550 doesn't have a CAN peripiheral, and doesn't have the grunt to be able to software simulate one, except as Ttelmah says as the very lowest bit rates, so you need an external controller, again as Ttelmah said:

    Quote:
    Something like the MCP2515. Driver for this (or it's older brother the 2510), is in the drivers directory (can-mcp251x).


    You also need the transceiver/level translator such as the MCP2551. However, that's not really recommended for new designs. Microchip recommend using the MCP2561/62, improved versions capable of split Vdd operation - i.e. 5V for CAN, but 3.3V for PIC/interface - and available in smaller packages better suited to today's production techniques, but not the hobbist/student, instead.
    705150



    Joined: 25 Apr 2013
    Posts: 14

    View user's profile Send private message

    PostPosted: Tue May 12, 2015 6:40 am     Reply with quote

    thank you Rf_developer for your helpfull reply, i have another project for the future where the pic is on 3.3v and need it to connect to a 5v canbus so the mcp2561 does come handy
    newguy



    Joined: 24 Jun 2004
    Posts: 1907

    View user's profile Send private message

    PostPosted: Tue May 12, 2015 7:58 am     Reply with quote

    705150 wrote:
    thank you Rf_developer for your helpfull reply, i have another project for the future where the pic is on 3.3v and need it to connect to a 5v canbus so the mcp2561 does come handy


    Yeah, no. You can mix 5V CAN interface chips on the same bus with 3.3V interface chips. The actual CAN bus signalling levels are compatible with either a 3.3V or 5V system Vdd.

    When I get into work I'll post the part number of my favourite 3.3V interface chip.
    newguy



    Joined: 24 Jun 2004
    Posts: 1907

    View user's profile Send private message

    PostPosted: Tue May 12, 2015 9:31 am     Reply with quote

    My go-to choice for CAN transceiver is the Texas Instruments SN65HVD233MDREP.
    705150



    Joined: 25 Apr 2013
    Posts: 14

    View user's profile Send private message

    PostPosted: Tue May 12, 2015 12:40 pm     Reply with quote

    The thing is i used a 18f25k80 at 3.3v vdd but i also connected the mcp2551 at the 3.3v, but it behaved rather chaotic and damaged 2 can drivers until i switched to 5v at which its curently working fine right now.

    But i have a rfm73 2.4ghz tranceiver that works at 3.3v spi that i have to use later. This is for a car alarm and the rfm73 is for the remote. I have to find a way to connect them all togheter.

    Thank you all for your help so far, its good to find nice people here.
    newguy



    Joined: 24 Jun 2004
    Posts: 1907

    View user's profile Send private message

    PostPosted: Tue May 12, 2015 3:59 pm     Reply with quote

    The MCP2551 is rated for 5V only - that's why it acted erratically. Use a CAN transceiver rated for 3.3V operation and your entire project can use a 3.3V power supply rail....no need for 5V at all.

    It also needs to be clearly restated: you can connect any CAN project/PCB to any other CAN project/PCB and it doesn't matter if one uses a 5V system and the other a 3.3V system power supply.
    705150



    Joined: 25 Apr 2013
    Posts: 14

    View user's profile Send private message

    PostPosted: Tue May 12, 2015 5:05 pm     Reply with quote

    thank you all again for your reply, i hope to be able to return the help some day, for now
    Display posts from previous:   
    Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
    Page 1 of 1

     
    Jump to:  
    You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot vote in polls in this forum


    Powered by phpBB © 2001, 2005 phpBB Group