Dual 18F Program Ideas and strategy SPI and CAN.


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default Dual 18F Program Ideas and strategy SPI and CAN.

    I'm building a MITM 'Man in the Middle' CAN - CAN device to manipulate some CAN 500kbps data.

    I'm happy working with pic CAN rxd and txd and am using 2 x pic18F2680 32mhz joined with hardware SPI Master/Slave 8mhz for prototype testing.

    The hardware can be easily upgraded to a 64mhz 18F26K80 and 16mhz SPI bus later once I have a sensible software strategy.

    Basically the hardware setup is as follows. (This all works)

    CANBUS1 <<<>>> PIC18F2680 <<< SPI 8mhz >>> PIC18F2680 <<<>>> CANBUS2

    Whatever is received on CANBUS1 needs to be sent out on CANBUS2 and vice versa.

    There is even a Heath Robinson video of it working if you have a few minutes..




    As described this does operate quite well, but i'm dropping a few CAN packets and am after some ideas on the best/fastest software strategy..

    I can poll flags or use DT Interrupts on the CAN and SPI modules.
    I could add a ring buffer at both ends maybe for RX and TX.

    I've read up on the CAN and SPI errata for the PIC and done a lot of reading and that all seems to be working.
    The SPI is currently configured as Master & Slave...
    I could add more handshaking lines between the pics as there is a lot of spare IO if that would help throughput.

    Now packets on the two CAN busses might not arrive at the same time or intervals/frequency. How to deal with that?

    Maybe I should join two complete ports together on the pics and clock out data a byte at a time?
    I could join PIC ports A directly to each other with a 1k current limit resistor on each line to prevent direct shorts.
    Would that be quicker/easier than the hardware 8mhz SPI?

    Anyone have any other cunning ideas?

    Basically at the moment my process is run the SPI bus as fast as possible between the PICS,
    and then as data appears on the CANRX busses (poll or interrupt detected) drop it onto the SPI to clock it across to the other PIC for onward transmission.

    Thanks in advance for ideas..

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Dual 18F Program Ideas and strategy SPI and CAN.

    The 500kbps CAN bus is not fully loaded so I think I might have cracked it for now.

    I added a control line from the Slave to the Master to basically say 'Hold on Boss i'm not ready'.

    This also keeps the SPI in sync and means CAN packets are no longer getting missed.

    I'm going to load up both sides of the CAN bus with a load more packets and see if it falls over.

    I realise time is tight.

    I need to add a counter to see how many cpu cycles are unused at present?
    Not sure how to do that...

    This is it working.. for now..


  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Dual 18F Program Ideas and strategy SPI and CAN.

    I made a small standalone test board using 2 x 64mhz 18F26K80 pics and that works well with the SPI bus running at 4mhz.

    I'll post the final pbp code when finished..

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Dual 18F Program Ideas and strategy SPI and CAN.

    Hi. Is this an automotive application? Why do you need to relay the CAN bus data?

    Thanks,
    Ioannis

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Dual 18F Program Ideas and strategy SPI and CAN.

    Most likely, for chip-tuning purposes...

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Dual 18F Program Ideas and strategy SPI and CAN.

    Yes automotive.

    I have already developed several popular devices to control Honda Hybrid vehicle systems or modify OEM behaviour.

    The desire to modify cars has not really changed.
    But instead of tweaking carbs and points, we now reverse engineer electronic systems to unlock potential or push the envelope.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Dual 18F Program Ideas and strategy SPI and CAN.

    Very interesting!

    Will follow!

    Ioannis

Similar Threads

  1. 18F/example writing to program memory?
    By Experimenter in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st October 2014, 13:05
  2. Dual power source
    By Demon in forum Off Topic
    Replies: 11
    Last Post: - 12th January 2014, 15:16
  3. Clock and Dual Termometer
    By fratello in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 3rd February 2011, 18:17
  4. SPI on a pic without hardware SPI?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th April 2006, 14:29
  5. MCP4922 Dual DAC
    By J_Brittian in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th October 2005, 19:39

Members who have read this thread : 2

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