CAN header and EXT asm question


+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2022
    Posts
    14

    Default 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

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default 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

    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.
    Warning I'm not a teacher

  3. #3
    Join Date
    Apr 2022
    Posts
    14


    Did you find this post helpful? Yes | No

    Default 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

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default 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
    Warning I'm not a teacher

  5. #5
    Join Date
    Apr 2022
    Posts
    14


    Did you find this post helpful? Yes | No

    Default 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

  6. #6


    Did you find this post helpful? Yes | No

    Default 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.

  7. #7
    Join Date
    Dec 2021
    Location
    Illinois, USA
    Posts
    12


    Did you find this post helpful? Yes | No

    Default 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

  8. #8


    Did you find this post helpful? Yes | No

    Default 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.

    Attached Files Attached Files
    Last edited by retepsnikrep; Yesterday at 05:33.

  9. #9


    Did you find this post helpful? Yes | No

    Default 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.
    Last edited by retepsnikrep; Today at 08:36.

Similar Threads

  1. A header wizard
    By cncmachineguy in forum PBP Wish List
    Replies: 229
    Last Post: - 24th February 2011, 04:21
  2. ASM question
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th February 2011, 17:37
  3. Question about using ASM interupt with PBP
    By cncmachineguy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th December 2010, 18:04
  4. ASM question
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 23rd March 2010, 00:33
  5. question about how to implement ASM and ENDASM
    By karenhornby in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th March 2008, 09:21

Members who have read this thread : 12

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts