CAN header and EXT asm question
I have been working on a CAN file that I can include for a PIC18F46K80 that has an internal ECAN module. The SFR registers for this function total to approximately 278 registers! Fortunately, many of them repeat their function. Since I don't want to hardcode all these registers, I have been looking for a way to address them like an array. In the main code you have a variable that determines which block of registers you are sending the data to. It was suggested to me to use the EXT function and offsets to accomplish this.
Code:
@CAN_Buffer = B2D0 'load CAN_Buffer with the address of B2D0
CAN_Buffer VAR BYTE EXT 'tell PBP it is byte sized but doesn't need to assign space
I think I can then point at the next address by using CAN_Buffer+1 = .......
Now the catch. In the 18f46k80 and probably others, the SFR's cross bank segments. Do I have to declare the bank to use the EXT function? I have the CAN bus speed selection worked out but now want to be able to point at the various buffer spaces. Any ideas?
Thanks
Re: CAN header and EXT asm question
what you propose makes little sense to me, keep in mind my canbus knowledge is poor.
1. there are only 8 B2Dx type registers , to index past that leads you to all sorts of different register types
2. B2D0 is neither the top or the bottom of the BnDx type registers why start there
something like
@CAN_BufferB2 = B2D0 'load CAN_Buffer with the address of B2D0
@CAN_BufferB1 = B1D0
CAN_BufferB2 VAR BYTE EXT 'tell PBP it is byte sized but doesn't need to assign space
CAN_BufferB1 VAR BYTE EXT
might make mores sense
Quote:
I think I can then point at the next address by using CAN_Buffer+1 = .......
more like CAN_BufferB2[0+index] = .......
or
CAN_BufferB1[index] = .......
index=index+1
Its hard to see what you would gain.
Re: CAN header and EXT asm question
Hi Richard,
you are correct that there are only 8 registers like B1 or B2 D0. Those are only the data registers for one buffer. There are, however, 276 registers associated with the other elements in the CAN module. Mask registers, filter registers, registers that can be either transmit or receive. There are 14 registers associated with the B0 buffer. B0CON, B0D0 - B0D7, B0DLC, high and low address bytes and high and low extended address bytes. There are six "B" arrays. What I want to do is point at one of registers and load them with the 14 bytes of data from a Temp_CAN array with 14 elements. That way I can make use of any of the buffers without having to hard code B0CON .... B1CON .... etc. I hope this makes more sense now.
Thanks,
Paul
Re: CAN header and EXT asm question
as long as the pattern is consistent over the entire range then it should work
pic18 arrays are not bank limited so as long as you use array indexing methods the banking should no be an issue
Re: CAN header and EXT asm question
Thanks Richard, that was what I was hoping to hear! I'll get back to work on the CAN program now!
Paul
Re: CAN header and EXT asm question
Be interested to see what you were working on.
I've done quite a bit on CAN with PBP.
Re: CAN header and EXT asm question
I have been working on a CAN interface file where you pass a few initial set up parameters, speed etc. and it selects and sets the appropriate registers. When you want to send a frame, you load a buffer and pass it off to the routine which finds the first available transmit buffer and sends it. I have the DT interrupts so I can enable the ones for the CAN if needed, although in my application, I don't. I only handle mode 1 and mode 2 of the CAN bus. What have you been doing with CAN?
-Paul
2 Attachment(s)
Re: CAN header and EXT asm question
Paul. Can we see that?
I have used pics with the internal CAN module and a can line driver and ones without but with an external microchip mini CAN board and line driver.
I built a Honda CR-Z/Insight Hybrid car MITM control device.
It intercepts and modifies motor control signals allowing the driver to manually control the IMA motor.
It sits in the IMACAN line relaying thousands of OEM messages back and forth and also listens on a separate FCAN line to more messages and control commands.
It uses a 18F26K80 at 64mhz and 3 el-cheapo aliexpress $5 SPI CAN boards.
My code is attached.
IMAC&C is the IMA control MITM device. This uses the cheap CAN boards.
OBDIIC&C is an FCAN device to talk to the car like an OBDII diagnostic tool. This uses the internal pic CAN module.
https://youtu.be/e8HzFkwf7wM
Re: CAN header and EXT asm question
Interface board with SPI controlled MCP 2515 and line driver to use with non CAN enabled PIC's
https://www.aliexpress.com/item/1005006850683509.html
Line driver to use with CAN enabled PIC's.
https://www.aliexpress.com/item/1005006209071522.html
You get the idea.. Cheap as chips..
My YT channel has a lot of PIC CAN tinkering stuff. @retepsnikrep
On Insightcentral.net and the CRZforum.com is tons of stuff from over the years.
2 Attachment(s)
Re: CAN header and EXT asm question
Earlier CAN MITM prototypes.
One using 16F1825 at 32mhz and one using 18F26K80 at 64mhz.
It was possible to drive one of those serial data to RCA video gadgets as well.
This made a nice little very cheap dash mounted text display for info and debugging.
Attachment 9970
Attachment 9971
Re: CAN header and EXT asm question
Watch out for the slew rate control bit in PICS.
It defaults to on in the PIC18F26K80!
This screwed me for hours as the SPI just kept falling over above 1mhz.
Not enough drive power for the circuit capacitance etc.
Once I found the SLRCON register and cleared it the SPI bus would run happily at 10mhz with the PIC overclocked to 80mhz.
In the end I dropped back to 8mhz and 64mhz for the bus and pic respectively.
IIRC 10mhz SPI is the maximum for the MCP2515 running with an 8mhz crystal.
Re: CAN header and EXT asm question
Anyone got anything else to add/share please??
I bared my feeble CAN soul, now it's your turn.
Re: CAN header and EXT asm question
Very useful info that are posted in this thread, but I am afraid that CAN topic is not very popular!
Thanks anyway for your kindness to share your experience.
Ioannis
Re: CAN header and EXT asm question
I played with the MCP25625 (CAN controler and driver) using the SPI peripheral on the 18F57Q53 a while back (just looked, turns out it's 4 years ago now, bloody hell...).
My intention was to make a "universal" driver for it and it looks like I did get most of the way but then lost interest it (which is what usually happens) since I didn't really had a need and/or use for it at the time.
You could
Code:
#DEFINE CAN_OSCILLATOR 20
#DEFINE CAN_BITRATE 125000
And it would automatically set the CNF1-3 registers (to reasonable values) based on bitrate and oscillator speed. Low level read/write/modify register routines, medium level Load_Tx_Buffer & Read_Rx_Buffer routines and higher level like GetCANMessage seems to have been implemented. I need an actual project to finish it.