CANbus


Closed Thread
Results 1 to 24 of 24

Thread: CANbus

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Location
    Bavaria
    Posts
    28

    Default

    CAN my be a little confusing in the beginning, but I am sure you will work into this.
    PIC BASIC will not help you much regarding CAN communication, you will have to set all registers by hand.
    As preparation you should do the following things:

    1. check if your CAN transceiver has an enable pin and check its status
    2. get the baudrate generator calculator from Microchip to calculate BRGCON register settings

    Then you can prepare your code
    3. configure you CANTX and CANRX pins correctly
    4. set CANCON register to 128 for config mode
    5. configure the BRGCON1..3 with the calculated values
    6. configure the identifier registers TXB0SIDH and TXB0SIDL to generate the required message ID
    7. configure the data length register TXB0DLC to match the length of your CAN message
    8. configure the CIOCON register (usually CAN recessive high, bit 4 set)
    9. set CANCON to 0 for normal mode
    10. copy your CAN data to TXB0D0...TXB0D7
    11. set the TXB0CON register to 8 to send your CAN message

    .. and off you go!

  2. #2
    Join Date
    Apr 2009
    Posts
    15

    Default

    Quote Originally Posted by inse View Post
    CAN my be a little confusing in the beginning, but I am sure you will work into this....
    Thank for your step-by-step guide! I'll try to begin with the project this weekend.

    Regards

  3. #3
    Join Date
    Apr 2009
    Posts
    15

    Default

    Well, I've connected the board to a PC using a CANUSB adapter listening at 100Kbps, but does not receive anything. This is the code (18F258+MCP2510 20Mhz):

    Code:
    define OSC 20
    
    TRISB = %000001000 'portb.2 output, portb.3 input
    CANCON = $80 'configuration mode 
    'Set Data Rate based on 20Mhz to get 100 kbs:
    BRGCON1 = $04 
    BRGCON2 = $BF 
    BRGCON3 = $02 
    
    CIOCON = $10
    TXB0SIDH = $0 
    TXB0SIDL = $1 
    CANCON = $0 'normal mode 
    
    '
    ' Program
    '
    Main: 
            TXB0DLC = 8 
            TXB0D0 = 65
            TXB0D1 = 66
            TXB0D2 = 67
            TXB0D3 = 68
            TXB0D4 = 69
            TXB0D5 = 70
            TXB0D6 = 71
            TXB0D7 = 72
            TXB0CON = 8
        pause 1000
    Goto main
    End
    What's wrong?
    Last edited by zx81sp; - 21st February 2010 at 17:27.

  4. #4
    Join Date
    Jul 2007
    Location
    Bavaria
    Posts
    28

    Default

    Your program looks OK at first glance altough I didn't verify the BRG values.
    What puzzles me is: do you really use an PIC18F258 in combination with an MCP2510?
    Or do you use the PIC18F258 with the MCP2551 CAN transceiver as mentioned earlier?
    The MCP2551 has a standby pin - how is it controlled?
    It must be tied low for operation!
    Check this and we can do further examination on the code.
    Are you sure you have set up and connected your CAN-USB adaptor correctly?
    A scope could show you if there is any activity on the bus.

  5. #5
    Join Date
    Apr 2009
    Posts
    15

    Default

    Quote Originally Posted by inse View Post
    Your program looks OK at first glance altough I didn't verify the BRG values.
    I've got the BRG values using Microchip Can Bit Timing Calculator (from www.intrepidcs.com), it claims to be compatible with MCP2510, I think that the values are same for my MCP2551, also tried with the default values that the calculator shows (03/BF/07) but anyway nothing changes.
    What puzzles me is: do you really use an PIC18F258 in combination with an MCP2510?
    Or do you use the PIC18F258 with the MCP2551 CAN transceiver as mentioned earlier?
    Sorry, the right combo is 18F258+MCP2551.
    The MCP2551 has a standby pin - how is it controlled?
    It must be tied low for operation!
    RS Pin is connected to GND
    Check this and we can do further examination on the code.
    Are you sure you have set up and connected your CAN-USB adaptor correctly?
    When I connect the CANUSB to the CAN network I can see the traffic, so I think that the problem it's not there. When I connect the adapter directly to the board I can't see activity, if the PBP code is right I must receive a command every second.

    Thanks for your help!
    Last edited by zx81sp; - 21st February 2010 at 21:36.

  6. #6
    Join Date
    Jul 2007
    Location
    Bavaria
    Posts
    28

    Default

    Another point to check just came into my mind:
    The PIC you are using has internal PLL - did you check its configuration?

  7. #7
    Join Date
    Apr 2009
    Posts
    15

    Default

    Quote Originally Posted by inse View Post
    Another point to check just came into my mind:
    The PIC you are using has internal PLL - did you check its configuration?
    Not sure if this is what you ask for, but I've checked the programmer options, OSC is setting to HS, there is a option for HS w/PLL on but it's not enabled.

    Can you verify the BRG values?
    Last edited by zx81sp; - 22nd February 2010 at 20:38.

Similar Threads

  1. canbus
    By nono2002 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 1st January 2014, 20:35
  2. Canbus
    By Tobias in forum Off Topic
    Replies: 0
    Last Post: - 22nd September 2008, 23:54
  3. Using the 18F2480 CAN CANBUS
    By bwarb in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th August 2005, 13:45
  4. CANbus
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th March 2005, 15:43

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts