News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Using CAN bus on the 18F25K83

Started by kcsl, Jul 17, 2024, 01:31 PM

Previous topic - Next topic

kcsl

Has anybody managed to get the CAN controller built into some PICs like the 18F25K83 to work?
There is depressing little information around that I can find and I seem to be getting nowhere very slowly.
I really don't want to do down using something like the MCP2515.

Does anybody have any example code that I could have a peek at please?

Kind regards,
Joe
There's no room for optimism in software or hardware engineering.

RGV250

Hi Joe,
I have had it working on older 18F258/2580 etc and the like, that was on an older version of the compiler and I keep meaning to revisit. From memory the new devices are slightly different. How quick are you looking for it as I will see if I can did it out and have another look.

Bob

kcsl

Hi Bob,
Thanks for the reply.

I've managed to get it working. Ended up buying a CAN bus analyser which arrived today, and it showed pretty quickly what the problems were.
In the end it comes down to setting the BRGCON1, 2 & 3 registers correctly which I found a nightmare. There are calculators on-line but the Microchip plug-in for MPLAB is useless as it doesn't cover the PIC18's. Most of the calculators talk about clock frequency, but don't make it clear if it's the crystal frequency, fosc / 4, or something else.

In the end I managed to reverse engineer an Arduino CAN library that uses the MCP2515; which is almost identical internally to the CAN module in the 18F25K83, to figure what registers need settings, and then some trial and error managed to work out the register values for different speeds.
Also not really knowing anything about CAN bus didn't help and getting to grips with this was a steep learning curve.

More experimentation now required to see how the PIC performs using the internal OSC as opposed to an XTAL.

Regards,
Joe
There's no room for optimism in software or hardware engineering.

RGV250

I use the Kvaser timing calc with the Microchip MCP device and then manually set the bits in BRG1,2,3
I did have a library which makes life easier but I had a hardware failure which wiped out all my test boards. The ground pin of the voltage regulator broke and fried all my boards with 15 volts instead of 5.
Never got round to fixing them and testing it.

Bob