News:

;) This forum is the property of Proton software developers

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

RGV250

Hi Joe,
How are you getting on with the 18F25K83, I am looking at making new boards as I messed up my older ones and it looks like the new devices are a quarter of the price of the old ones I used.
I saw you had issues with these new ones which you have resolved, would you be able to post your code or a simple example if possible.

Regards,
Bob

kcsl

Hi Bob,

I did get code working for the CAN module on the 18F25K83 and built a demo device for the customer which worked great, but ultimately had to abandon that device as it just doesn't have enough RAM to support a NMEA 2000 CAN stack, so moved to the 18F27Q83, which has loads of RAM, Flash memory, was cheaper but unfortunately has a completely different CAN hardware module to the 25K83. None of the code was portable from the original PIC, so I basically had to start again.

I could probably dig out some code, but I'd have to cut out all the client specific application code, but it would have all the CAN initialisation code and routines for talking to the CAN module. The code is horrible because at the time I had no idea what I was doing.

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

RGV250

Hi Joe,
That would be great, I did write a CAN library years ago but I have not looked at it for years as I trashed all my boards, fried them due to a voltage regulator screw up. Anything you have will be good as like you know, the datasheets are enormous. Both the 25K83 and the 27Q83 would be nelpful if you can sort it.

Regards,
Bob