Simple questions on the CAN

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Simple questions on the CAN

Post by Coccoliso » Tue Mar 11, 2014 12:14 pm

Hello,
a few simple questions on the CAN:
1) on the CAN lan must have at least one master and at least one or more slaves
2) the communication between master and slave takes place on a message identifier
3) If you send the message you take care to name uniquely identifies the message and then not take care of those who interpret since it is the receiver to interpret it if it recognizes
4) each node does (master or slave ) not have an address
5) the most distant node must close the CAN line with a termination resistor

I understand it ..?

The next question before I zap :lol: a couple of PIC for testing purposes, you can connect CAN 2 pic terminals (with some pullup resistor) with each other without using MCP2551 ?

Jerry Messina
Swordfish Developer
Posts: 1245
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Simple questions on the CAN

Post by Jerry Messina » Tue Mar 11, 2014 3:21 pm

1) on the CAN lan must have at least one master and at least one or more slaves

It's not really a master and slave bus, but you must have at least two devices to generate the proper ACK


2) the communication between master and slave takes place on a message identifier

Between devices, yes


3) If you send the message you take care to name uniquely identifies the message and then not take care of those who interpret since it is the receiver to interpret it if it recognizes

The message ID, along with the receiver filter masks determine who sees the message. Many receivers can see the same message.


4) each node does (master or slave ) not have an address

That's correct... each device listens to messages that match its Message ID filter settings


5) the most distant node must close the CAN line with a termination resistor

Definitely recommended. Also, don't forget that you need THREE wires... CANH, CANL, and GND


6) you can connect CAN 2 pic terminals (with some pullup resistor) with each other without using MCP2551 ?

No, for the bus to work properly you need a CAN transceiver

Jerry Messina
Swordfish Developer
Posts: 1245
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Simple questions on the CAN

Post by Jerry Messina » Tue Mar 11, 2014 5:59 pm

After I posted, I got to thinking about the issue if not using a transceiver, and remembered that for most pics the CANTX pin can be set to an open-drain/tristate mode using the CIOCON register. I also remembered seeing a siemens app note about something similar a while back... http://www.mikrocontroller.net/attachme ... AP2921.pdf

I did some digging around, and check this out - http://electronics.stackexchange.com/qu ... -a-can-bus

It's not CANbus compliant, but it should let you experiment or link a few chips together in a simple network.

If you try it, let us know how it works.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Simple questions on the CAN

Post by Coccoliso » Tue Mar 18, 2014 1:32 pm

Hello,
excuse the delay in replying but it is a week that I'm working and I'm having trouble with the 18F4685.
Since I use the internal oscillator can not figure out if the problem is the CONFIG or the pullup circuit that does not work.

I am using the file IntOsc.BAS:

Code: Select all

#if _Device in (18F4685)
    Config
            OSC =  IRCIO67,
            PWRT = On,
            WDT = On, 
            MCLRE = off,
            LVP = OFF,
            CP0 = OFF,  
            PBADEN = OFF,
            STVREN = off,  
            BOREN  = off    
#endif
 
 Include "SetDigitalIO.bas"
 SetAllDigital()

#if _device in (18F4685)
    OSCCON = %01110000     ' 8MHZ
    // OSCCON = %01100000     ' 4MHZ        
    OSCTUNE = %01000000    ' PLL = fOSC x 4 - 32MHz
#endif
 
.. and in the module CAN_Echo.BAS of Florin Andrei Medrea I set as follows:

Code: Select all

Device  = 18F4685   '18F458
Clock   = 32        '40

Include "intosc.bas"
Include "CAN_lib"
Include "usart"
Include "SYS_lib"

Dim Can_Init_Flags, 
    Can_Send_Flags, 
    Can_Rcv_Flags, 
    Rx_Data_Len, 
    i               As Byte,
    RxTx_Data(8)    As Byte,
    Tx_ID, 
    Rx_ID           As LongWord,
    Msg_Rcvd, 
    Msg_Sent        As Boolean

  
  ADCON1 = %11000110      // AD off
  CMCON = $07             // Comparator off
  WDTCON = 1
  
  ClrWDT
'  OSCTUNE = %01000000      // 16x4

  SetBaudrate(br115200)
  DelayMS(1000)
  Write("Hello World!",13,10)
After displaying the message "Hello world!" nothing more happens and my doubt is the WDT = On for which there is no WDTPS value.
I saw that the 18F4685 is among the MPU that Florin Andrei expected but I missing some configuration for this particular MPU.

HELP!

PS: I'm waiting for the MCP2551 CAN Transceiver .. so I can take the test as soon as it arrives. :wink:

Jerry Messina
Swordfish Developer
Posts: 1245
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Simple questions on the CAN

Post by Jerry Messina » Tue Mar 18, 2014 2:04 pm

The default setting for the 18F4685 WDTPS is 128 (set at the bottom of Includes\18F4685.bas). You can always increase this
if required by adding "config WDTPS = xxx", where xxx = 256, 512, 1024, 2048, 4096, 8192, 16384, 32768.

However, using the internal osc with CANbus isn't recommended, esp with older chips like the 4685 which have a big variation in the osc tolerance.
CAN specs limit the osc difference between nodes to 1.58% total, and that's for speeds < 125Kbps.

You might be able to get it to work but you'll likely have to do a lot of adjusting of the various CAN bit timings.
I'd recommend you use at least a ceramic resonator of < 0.5%, preferably an xtal.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Simple questions on the CAN

Post by Coccoliso » Wed Mar 19, 2014 12:43 pm

Hello!

Latest news with MPU 18F4685 :

- is confirmed that internal oscillator in CAN is unusable (8/32 does not matter) and all ok with 20MHz XTAL in HS mode.
- unfortunately without MCP2551s the circuits affected by the noise and the connection between the pic was as short as possible (max. 20 cm) that which does not happen with the transceivers.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Simple questions on the CAN

Post by Coccoliso » Tue Apr 08, 2014 10:24 pm

Hello,
there are examples on how to enable an RX interrupt on CAN message?
Can you direct me about it?
Thanks.

Post Reply