Shop OBEX P1 Docs P2 Docs Learn Events
Are the jm_mcp2515 object CNF values correct? — Parallax Forums

Are the jm_mcp2515 object CNF values correct?

sccoupesccoupe Posts: 118
edited 2014-11-26 07:51 in Propeller 1
I'm using the jm_mcp2515 object and it seems to work ok for most testing, but sometimes there are issues with it not playing nice with other CAN modules. Its specifically being used at 1mbit. Checking into the speed setting set by CNF1, CNF2, and CNF3, the values don't seem to match any that are on the list provided by the Kvaser calculator. The values below are what are called out in the jm_mcp2515.spin module.

1000:
write(CNF1, $00)
write(CNF2, $C9)
write(CNF3, $02)
return 1000

Wouldn't $00, $91, and $01 be more appropriate as suggested by the Kvaser site given the unknowns of a CAN network? I haven't tested these values yet, but would like to get some further understanding on what they are used for and why the existing spin code is set the way that it is set.

Thanks

Comments

  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-11-25 17:29
    I think it may be best that I stop releasing objects....
    I haven't tested these values yet, but would like to get some further understanding on what they are used for and why the existing spin code is set the way that it is set.

    You know, Microchip makes a data sheet available which if you don't have, you should download and study before criticizing my code. I'm not saying that you aren't correct, but you're just flailing, hoping someone will back you up which saves you the hard work of studying the data sheet. Step up, read the data sheet, show me where I erred, and I'll change my code.

    -- http://ww1.microchip.com/downloads/en/DeviceDoc/21801G.pdf

    That particular object is running in a commercial application without issue. To be fair, all other nodes are using the same code so that could be masking things. Still, I validated the object and hardware with a commercial CAN bus adapter and software.

    -- http://www.phytools.com/PCAN_USB_Adapter_CAN_USB_Interface_IPEH_002021_p/ipeh-002021.htm
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-11-25 17:43
    JonnyMac wrote: »
    I think it may be best that I stop releasing objects....
    Please do not do this because of one persons issues. Your work is AWESOME and I for one can say that I have used many of your objects with GREAT success.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-11-25 18:01
    Sadly, it's not one person. It gets tiresome having to defend myself from those who refuse to read a data sheet.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-11-25 18:05
    JonnyMac wrote: »
    Sadly, it's not one person. It gets tiresome having to defend myself from those who refuse to read a data sheet.
    Ummm.... I hope I'm not one of the guilty parties. If so, I apologize. I would certainly miss your contributions and the help you've given me over the years!
  • sccoupesccoupe Posts: 118
    edited 2014-11-25 18:19
    Jon,

    I'll step up here and apologize if it sounds like i'm criticizing the work that you put out to the community freely. Now that I re-read how I put it, it does sound a little off. As far as looking for flailing agreement, I beg to differ. Your code comments that the CNF values are from the Kvaser calculator and is where my question is from. If all nodes are using the same bit timing, them I'd expect that everything would work fine. However, the current situation is with equipment of unknown bit timing, so one can only hope that it is standard. Now back to the MCP2515 setup... If a rate of 1mbit with a 16mhz crystal is put into the calculator and up to 1.5% error allowed, none of the CNF values in the list line up with the ones in your code, so their must be a reason for it.
    In the future, i'll be more sensitive to how my questions are worded. Emotion is so difficult to text out.

    Thanks
  • pmrobertpmrobert Posts: 673
    edited 2014-11-25 18:19
    JonnyMac wrote: »
    Sadly, it's not one person. It gets tiresome having to defend myself from those who refuse to read a data sheet.
    -Never mind-
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-11-25 18:25
    the values don't seem to match any that are on the list provided by the Kvaser calculator

    Really? Here's the output from that calculator:

    attachment.php?attachmentid=112047&d=1416968688

    See the values in the circle? I know what you're thinking: "But your CNF2 value is $C9, not $89!"

    Let's have a look at my code, shall we? -- just the header portion of the "offending" method.
    pub set_baud(kbps) | mode                                               ' section 5.0 of docs
    
    '' Set baud for 16MHz FOsc
    '' -- http://www.kvaser.com/en/support/bit-timing-calculator.html
    '' -- manually added SAM bit to CNF2 (for 3x buss sampling)
    '' -- mode must be set to CONFIG to change baud
    

    Note that pesky second comment: manually added SAM bit to CNF2 (for 3x buss sampling)

    If we take the time to crack open the data sheet (hint, hint), we find the SAM bit is bit6 ($40) of CNF2. $89 | $40 is.... $C9.

    Case closed.

    Am I irritated? You bet. Take a shot at me if you want, but if you're unwilling to understand my code before criticizing it, be prepared to unleash my inner tiger.

    Happy Thanksgiving everyone!
    768 x 845 - 372K
  • sccoupesccoupe Posts: 118
    edited 2014-11-25 18:31
    So it was there and all well documented. No shots need to be taken, i'm still thankful for the help.

    Regards
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-11-25 18:35
    Ummm.... I hope I'm not one of the guilty parties.


    No, David. Your questions are always thoughtful.

    For those that don't know me, I don't mind being challenged -- in fact, I benefit from those exchanges. What I find tiresome is people challenging me (and others) without doing some basic research or attempting understanding.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-11-25 18:36
    It's behind us now. Good luck with your project.

    sccoupe wrote: »
    So it was there and all well documented. No shots need to be taken, i'm still thankful for the help.

    Regards
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-11-26 07:51
    For what it is worth, configuring the MCP2515 is not a one setup fits all.

    If you change the baud rate, you need to get new settings.
    If you have long wires or many drops, you may need to explore several alternative settings.
    If you don't have proper termination (at least a 300 ohm resistor), you are going to get reflections on the wire that will degrade performance.

    Even the calculators will give you more than one setting combination that may work. There is a bit of art in getting a high performance CANbus to operate smoothly.

    But if you have trouble, you need to consider that you are expecting too much speed or too much traffic on the CANbus.

    The documentation for the MCP2515 is a bit large, and requires reading until one understands it.
Sign In or Register to comment.