18F4580 CAN Bus & HBUSOUT


+ Reply to Thread
Results 1 to 7 of 7

Thread: 18F4580 CAN Bus & HBUSOUT1021 days old

  1. #1
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,942
    Thumbs Up
    Received: 26
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default 18F4580 CAN Bus & HBUSOUT

    Good afternoon all.

    I have 3 PIC18F4580 boards swapping data via CAN bus quite happily.
    I have added a known working MCP23017 I2C Port expander sub routine at the bottom of the code and it causes the CAN node to go into error, even though I don't call it. I would have thought that as I don't call the routine, it would be ignored by the program?


    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings
    Device = 18F4580
    Declare Xtal 12
    Include "MCP23017.inc"
    Config_Start
    OSC = HS ;Internal oscillator block, port function on RA6 and RA7
    FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    IESO = OFF ;Oscillator Switchover mode disabled
    PWRT = On ;PWRT disabled
    BOREN = BOHW ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    BORV = 1 ;VBOR set to 4.3V
    WDT = OFF ;WDT disabled (control is placed on the SWDTEN bit)
    WDTPS = 32768 ;1:32768
    PBADEN = OFF ;PORTB<4:0> pins are configured as analog input channels on Reset
    LPT1OSC = OFF ;Timer1 configured for higher power operation
    MCLRE = On ;MCLR pin enabled; RE3 input pin disabled
    STVREN = On ;Stack full/underflow will cause Reset
    LVP = OFF ;Single-Supply ICSP enabled
    BBSIZ = 1024 ;1K words (2K bytes) boot block
    XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    Cp0 = OFF ;Block 0 (000800-001FFFh) not code-protected
    CP1 = OFF ;Block 1 (002000-003FFFh) not code-protected
    CP2 = OFF ;Block 2 (004000-005FFFh) not code-protected
    CP3 = OFF ;Block 3 (006000-007FFFh) not code-protected
    CPB = OFF ;Boot block (000000-0007FFh) not code-protected
    CPD = OFF ;Data EEPROM not code-protected
    WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
    WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
    WRT2 = OFF ;Block 2 (004000-005FFFh) not write-protected
    WRT3 = OFF ;Block 3 (006000-007FFFh) not write-protected
    WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
    WRTB = OFF ;Boot block (000000-0007FFh) not write-protected
    WRTD = OFF ;Data EEPROM not write-protected
    EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
    EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
    EBTR2 = OFF ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
    EBTR3 = OFF ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
    EBTRB = OFF ;Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    '***********************************************
    '* Variable definitions *
    '***********************************************
    ' Some of the variables will not be used as the code is generic.
    ' EG, if this module node is set to 1 by the jumpers then NODE_1_DATA_xx
    ' variables are not used as they are for received messages and the
    ' identifier for the TRANSMIT_DATA_xx will be 1.

    Declare PortB_Pullups On
    SSPCON1 = %10101000
    SSPCON2 = %00000000
    SSPSTAT = %10000000

    Dim TRANSMIT_DATA_0 As Byte
    Dim TRANSMIT_DATA_1 As Byte
    Dim TRANSMIT_DATA_2 As Byte
    Dim TRANSMIT_DATA_3 As Byte
    Dim TRANSMIT_DATA_4 As Byte
    Dim TRANSMIT_DATA_5 As Byte
    Dim TRANSMIT_DATA_6 As Byte
    Dim TRANSMIT_DATA_7 As Byte
    Dim NODE_1_DATA_0 As Byte
    Dim NODE_1_DATA_1 As Byte
    Dim NODE_1_DATA_2 As Byte
    Dim NODE_1_DATA_3 As Byte
    Dim NODE_1_DATA_4 As Byte
    Dim NODE_1_DATA_5 As Byte
    Dim NODE_1_DATA_6 As Byte
    Dim NODE_1_DATA_7 As Byte

    Dim NODE_2_DATA_0 As Byte
    Dim NODE_2_DATA_1 As Byte
    Dim NODE_2_DATA_2 As Byte
    Dim NODE_2_DATA_3 As Byte
    Dim NODE_2_DATA_4 As Byte
    Dim NODE_2_DATA_5 As Byte
    Dim NODE_2_DATA_6 As Byte
    Dim NODE_2_DATA_7 As Byte

    Dim NODE_3_DATA_0 As Byte
    Dim NODE_3_DATA_1 As Byte
    Dim NODE_3_DATA_2 As Byte
    Dim NODE_3_DATA_3 As Byte
    Dim NODE_3_DATA_4 As Byte
    Dim NODE_3_DATA_5 As Byte
    Dim NODE_3_DATA_6 As Byte
    Dim NODE_3_DATA_7 As Byte

    Dim NODE_4_DATA_0 As Byte
    Dim NODE_4_DATA_1 As Byte
    Dim NODE_4_DATA_2 As Byte
    Dim NODE_4_DATA_3 As Byte
    Dim NODE_4_DATA_4 As Byte
    Dim NODE_4_DATA_5 As Byte
    Dim NODE_4_DATA_6 As Byte
    Dim NODE_4_DATA_7 As Byte

    Dim NODE_5_DATA_0 As Byte
    Dim NODE_5_DATA_1 As Byte
    Dim NODE_5_DATA_2 As Byte
    Dim NODE_5_DATA_3 As Byte
    Dim NODE_5_DATA_4 As Byte
    Dim NODE_5_DATA_5 As Byte
    Dim NODE_5_DATA_6 As Byte
    Dim NODE_5_DATA_7 As Byte

    Dim NODE_6_DATA_0 As Byte
    Dim NODE_6_DATA_1 As Byte
    Dim NODE_6_DATA_2 As Byte
    Dim NODE_6_DATA_3 As Byte
    Dim NODE_6_DATA_4 As Byte
    Dim NODE_6_DATA_5 As Byte
    Dim NODE_6_DATA_6 As Byte
    Dim NODE_6_DATA_7 As Byte

    Dim NODE_7_DATA_0 As Byte
    Dim NODE_7_DATA_1 As Byte
    Dim NODE_7_DATA_2 As Byte
    Dim NODE_7_DATA_3 As Byte
    Dim NODE_7_DATA_4 As Byte
    Dim NODE_7_DATA_5 As Byte
    Dim NODE_7_DATA_6 As Byte
    Dim NODE_7_DATA_7 As Byte
    Dim RX_NODE_NR As Byte ' Temp store for Identifier of received message
    Dim TX_NODE_NR As Byte ' This modules address as set by jumpers on PORTA 0:2.

    Dim NEW_MESSAGE As Bit
    Dim Timer1VAL As TMR1L.Word
    Dim i As Word
    Dim CAN_Err_Flag As Bit
    Dim COMSTAT_VAR As Byte
    Dim Led_Output As Byte
    Dim PotVar_0 As Byte

    Symbol IPEN = RCON.7
    Symbol TMR1IP = IPR1.0
    Symbol TMR1IF = PIR1.0
    Symbol TMR1IE = PIE1.0
    Symbol GIEH = INTCON.7
    Symbol GIEL = INTCON.6
    Symbol TMR1ON = T1CON.0
    '--------------------------------------------------------------------------------
    'Set up priority interrupts
    IPEN = 1 ' Enable priority interrupts.
    TMR1IP = 1 ' Set Timer1 as a high priority interrupt source
    TMR1IF = 0 ' Clear the Timer1 interrupt flag
    TMR1IE = 1 ' Enable Timer1 interrupts
    '-------------------------------------------------------------------------------
    'Set up Timer 1 Interrupt
    T1CON = 0x31 'Timer1 - 1:8 prescaler and act as timer
    Timer1VAL = 0 'Zero Timer
    TMR1ON = 1 'Start Timer running
    PIR1.0 = 0 'Clear timer 1 overflow bit
    PIE1 = 1 'Enable Timer1 interrupt
    GIEH = 1 'Set the global interrupt enable bits
    '-------------------------------------------------------------------------------
    Dim Button_Status As Byte
    Symbol Button1 = PORTB.0
    Symbol Button2 = PORTB.1
    Symbol button3 = PORTB.4
    Symbol Button4 = PORTB.5
    Symbol ErrorLed = PORTD.0
    Symbol IsrLed = PORTD.1

    'delayms 100
    GoSub INIT ' Initialize PIC & LCD
    DelayMS 100 ' Allow 100ms for the PIC to settle'
    On_Hardware_Interrupt GoTo INTERRUPT_ROUTINE 'Point to the Interrupt handler
    GoTo START ' Jump over the Interrupt routine

    '************************************************* ************************************************** ************************************************** *******************
    '* Interrupt Service Routine.
    'Determine if its a timed interrupt or CAN module interrupt.Also the ISR determines whether a Valid msg or CAN error.Interrupt has occured And Then proceeds accordingly
    '************************************************* ************************************************** ************************************************** *******************
    INTERRUPT_ROUTINE:
    Context Save
    If PIR1.0 = 0 Then GoTo CAN_MODULE_INTERRUPT
    Clear T1CON.0 'Stop timer

    TIMED_TRANSMIT_ROUTINE: 'If it wasn't the CAN module it must have been the timer Interrupt
    Toggle IsrLed 'Flash RED LED just to let me know it is doing something
    ''This is just to generate data for testing. Normally data wil be written to TRANSMIT_DATA_xx from elsewhere in the program.

    Button_Status.0 = PORTB.0
    Button_Status.1 = PORTB.1
    Button_Status.2 = PORTB.4
    Button_Status.3 = PORTB.5
    PotVar_0 = ADIn 0

    TRANSMIT_DATA_0 = TRANSMIT_DATA_0 + 1
    If TRANSMIT_DATA_0 = 255 Then TRANSMIT_DATA_0 = 0

    TRANSMIT_DATA_1 = TRANSMIT_DATA_1 + 1
    If TRANSMIT_DATA_1 = 255 Then TRANSMIT_DATA_1 = 0

    TRANSMIT_DATA_2 = TRANSMIT_DATA_2 + 1
    If TRANSMIT_DATA_2 = 255 Then TRANSMIT_DATA_1 = 0

    TRANSMIT_DATA_3 = TRANSMIT_DATA_3 + 1
    If TRANSMIT_DATA_3 = 255 Then TRANSMIT_DATA_1 = 0
    'Down to here !!!

    TXB0D0 = TRANSMIT_DATA_0'Move data into transmit buffer 0
    TXB0D1 = TRANSMIT_DATA_1
    TXB0D2 = TRANSMIT_DATA_2
    TXB0D3 = TRANSMIT_DATA_3
    CANCON = %00001000 'Normal mode, transmit buffer 0
    TXERRCNT = 0 'Clear TX error counter
    TXB0CON = %00001001 'Start transmition, priority level 1
    WAIT_TX0_OK: If TXB0CON.3 = 1 Then WAIT_TX0_OK 'Loop until TX succesfull
    CANCON = %00000000 'Select CAN normal mode after transmission
    PIR1.0 = 0 'Clear Timer 1 overflow interrupt bit
    TMR1ON = 0 'Re-set timer to zero
    Set T1CON.0 'Re-start timer

    CAN_MODULE_INTERRUPT:
    If PIR3.0 = 1 Then GoTo RECEIVE_MSG
    If PIR3.5 = 1 Then CAN_Err_Flag = 1 : GoTo Exit_ISR
    '************************************************* *********************
    '* CAN Msg Received Routine *
    '* This routine is called when a message has been received into RXB0. *
    '* The routine reads the Low identifier Byte And Then shifts the bits *
    '* right x 5 to get the number of the node transmitting the message. *
    '************************************************* *********************
    'It could probably be done better with indirect addressing but I only need 6 nodes !
    'It also makes the code more readable and understandable when I look at it in 6 months time.
    RECEIVE_MSG:

    RX_NODE_NR = RXB0SIDL >> 5 'Shift bits right x 5 to determine which node sent
    'current message.
    If RX_NODE_NR = 1 Then GoTo MESSAGE_FROM_NODE_1 'go to routine for that message.
    If RX_NODE_NR = 2 Then GoTo MESSAGE_FROM_NODE_2
    If RX_NODE_NR = 3 Then GoTo MESSAGE_FROM_NODE_3
    If RX_NODE_NR = 4 Then GoTo MESSAGE_FROM_NODE_4
    MESSAGE_FROM_NODE_1:
    NODE_1_DATA_0 = RXB0D0 'Copy data in receive buffer as it will be
    NODE_1_DATA_1 = RXB0D1 'overwritten by Next message
    NODE_1_DATA_2 = RXB0D2
    NODE_1_DATA_3 = RXB0D3
    NODE_1_DATA_4 = RXB0D4
    NODE_1_DATA_5 = RXB0D5
    NODE_1_DATA_6 = RXB0D6
    NODE_1_DATA_7 = RXB0D7

    NEW_MESSAGE = 1 'Set flag to update display
    GoTo Exit_ISR

    MESSAGE_FROM_NODE_2:
    NODE_2_DATA_0 = RXB0D0 'Copy data in receive buffer as it will be
    NODE_2_DATA_1 = RXB0D1 'overwritten by Next message
    NODE_2_DATA_2 = RXB0D2
    NODE_2_DATA_3 = RXB0D3
    NODE_2_DATA_4 = RXB0D4
    NODE_2_DATA_5 = RXB0D5
    NODE_2_DATA_6 = RXB0D6
    NODE_2_DATA_7 = RXB0D7

    NEW_MESSAGE = 1 'Set flag to update display
    GoTo Exit_ISR

    MESSAGE_FROM_NODE_3:
    NODE_3_DATA_0 = RXB0D0 'Copy data in receive buffer as it will be
    NODE_3_DATA_1 = RXB0D1 'overwritten by Next message
    NODE_3_DATA_2 = RXB0D2
    NODE_3_DATA_3 = RXB0D3
    NODE_3_DATA_4 = RXB0D4
    NODE_3_DATA_5 = RXB0D5
    NODE_3_DATA_6 = RXB0D6
    NODE_3_DATA_7 = RXB0D7

    NEW_MESSAGE = 1 'Set flag to update display
    GoTo Exit_ISR
    MESSAGE_FROM_NODE_4:
    NODE_4_DATA_0 = RXB0D0 'Copy data in receive buffer as it will be
    NODE_4_DATA_1 = RXB0D1 'overwritten by Next message
    NODE_4_DATA_2 = RXB0D2
    NODE_4_DATA_3 = RXB0D3
    NODE_4_DATA_4 = RXB0D3
    NODE_4_DATA_5 = RXB0D3
    NODE_4_DATA_6 = RXB0D3
    NODE_4_DATA_7 = RXB0D3

    NEW_MESSAGE = 1 'Set flag to update display
    GoTo Exit_ISR
    Exit_ISR:
    'preload timer 1 to 1000hz
    TMR1L = 160'193
    TMR1H = 15 '224
    COMSTAT = 0 'Clear CAN comminication status register
    RXB0CON = %00100000 'Set RXB0CON for next message
    PIR3 = 0 'Clear CAN bus error interrupt bits
    Context Restore 'Exit ISR and re-enable interrupts
    '************************************************* ******************
    '* CAN Error routine *
    '* At present this routine only places some registers on the LCD *
    '* turns on LED and halts program for diagnosing problem. *
    '************************************************* ******************
    CAN_ERROR:
    CAN_Err_Flag = 0 'Clear flag
    Cls 'Clear screen
    PORTD.1 = 1 'Turn on RED LED for CAN error
    Print At 1,1, "CAN error"
    Print At 2,1, Dec TXERRCNT
    Print At 2,5, Dec RXERRCNT
    Print At 2,9, Dec COMSTAT
    Print At 2,13, Dec PIR3
    Stop

    '***********************************************
    '* Start of Main Code *
    '***********************************************
    START:
    DelayMS 100 ' Wait for LCD to start
    Cls ' Clear screen

    '***********************************************
    '* Main program LOOP *
    '***********************************************
    Main_Loop:
    COMSTAT = 0 'Clear CAN comminication status register.
    INTCON = %00000000 'Turn off interrupts

    'Normal code routines go between here
    'Probably try using "Include" here so the CAN code never needs changing.
    If NEW_MESSAGE = 1 Then GoSub DISPLAY 'Only write to display if new message
    If CAN_Err_Flag = 1 Then GoTo NODE_ERROR

    'And here
    INTCON = %11000000 'Turn interrupts back on
    GoTo Main_Loop

    DISPLAY:
    Print At 1,1, "N1: ", Hex2 NODE_1_DATA_0," ",Hex2 NODE_1_DATA_1," ",Hex2 NODE_1_DATA_2," ",Hex2 NODE_1_DATA_3," ID:", Dec TX_NODE_NR
    Print At 2,1, "N2: ", Hex2 NODE_2_DATA_0," ",Hex2 NODE_2_DATA_1," ",Hex2 NODE_2_DATA_2," ",Hex2 NODE_2_DATA_3," "
    Print At 3,1, "N3: ", Hex2 NODE_3_DATA_0," ",Hex2 NODE_3_DATA_1," ",Hex2 NODE_3_DATA_2," ",Hex2 NODE_3_DATA_3," "
    Print At 4,1, "TXErr:", Dec3 TXERRCNT, " RxErr:", Dec3 RXERRCNT

    NEW_MESSAGE = 0
    Return
    '************************************************* *****
    '* PIC Initialization *
    '* Most of the CAN module registers are here Whether *
    '* used Or Not so I don't have to type them in again. *
    '************************************************* *****
    INIT:
    All_Digital = True 'Set all I/O to digital
    PORTA = 0
    ADCON1 = %00001111 'All Pins Digital
    ADCON2.7 =0
    Declare Adin_Res = 8
    Declare Adin_Tad = FRC
    Declare Adin_Stime = 20

    CMCON = 7 'Comparators Off
    'Set port direction On power up Or after reset
    PORTA = 0
    TRISA.3 = 1 'Set port direction - CAN Node ID Bit 0
    TRISA.4 = 1 'Set port direction - CAN Node ID Bit 1
    TRISA.5 = 1 'Set port direction - CAN Node ID Bit 2

    'Set up buttons for Node 1 on RB0, RB1, RB4 & RB5
    TRISB.0 = 1
    TRISB.1 = 1
    TRISB.4 = 1
    TRISB.5 = 1

    'Set port direction for CAN I/O
    'This is important, Proton does not set the port direction of the CAN I/O pins !!
    TRISB.2 = 0 'Set port direction - CANTx pin as output
    TRISB.3 = 1 'Set port direction - CANRx pin as input

    TRISC.0 = 0
    TRISC.1 = 0
    TRISC.2 = 0
    TRISC.3 = 0
    TRISC.4 = 0
    TRISC.5 = 0
    TRISC.6 = 0 'Set port direction - LED for diagnostics
    TRISC.7 = 0 'Set port direction - LED for diagnostics

    TRISD = 0 'Set port direction - LED for diagnostics & LCD Data (D4-7)
    'Set up PortE.0-2 for 3 bit CAN ID selection

    TRISE.0 = 0 '
    TRISE.1 = 0 'Set port direction - CAN Node ID bit 1
    TRISE.2 = 0 'Set port direction - CAN Node ID bit 2


    'Set state of port on power up or after reset
    PORTC.6 = 0 'Initialise output as off
    PORTC.7 = 0 'Initialise output as off
    PORTD = 255 'Initialise output as off

    '----------------------------------------------------------------------------------------------------------
    'CAN MODULE
    '----------------------------------------------------------------------------------------------------------
    'Set up the CAN module
    CANCON = %10000000 'Select CAN config mode
    TXB0CON = 0 'Clear transmit buffer 0 control register

    'set up CAN hardware
    BRGCON1 = 0x02 '%00000011 'SJW = 1 Tq, Tq = 4/Fosc
    BRGCON2 = 0xB8 '%11101100 'Phase seg 1 = 6 x Tq, Prop = 5 x tq, Sample 3 times
    BRGCON3 = 0x05 '%00000111 'Phase seg 2 = 8 x Tq
    Clear CIOCON.5 'ENDRHI 'recessive drives Tx to Vdd (required if using MCP 2551)

    TXB0DLC = %00000100 'RTR bit cleared, 8 byte data length
    RXB0DLC = %00000100 '8 byte data length
    'Determine node address (Set by jumpers On PORTA RA.5 - RA.3) to align with Standard identifier bits 2-0 which are
    'located in TXB0SIDL <7-5>. Not using ID's greater than 15 at this stage so TXB0SIDH is set to all zeros.
    PORTA = 0 'Clear PORTA before reading
    TX_NODE_NR = PORTA 'Read PORTA into TX_NODE_NR VAR
    TX_NODE_NR = TX_NODE_NR << 2 'Shift the value 2 places left to align with bits 7-5
    TX_NODE_NR = TX_NODE_NR & %11100000 'AND' with 11100000 to strip out unwanted bits (4-0)
    TXB0SIDH = %00000000 'Clear SIDH as only using lower 3 bits of 11 bit identifier (Bits 7-5 of TXB0SIDL)
    TXB0SIDL = TX_NODE_NR
    TX_NODE_NR = TX_NODE_NR >> 5 'Shift back for start up message

    RXM0SIDH = %00000000 'Set Receive mask 0 bits
    RXM0SIDL = %00000000 'Set Receive mask 0 bits

    RXM1SIDH = %00000000 'Set Receive mask 1 bits
    RXM1SIDL = %00000000 'Set Receive mask 1 bits

    RXF0SIDH = %00000000 'Set Receive filter 0 bits
    RXF0SIDL = %00000000 'Set Receive filter 0 bits

    RXF1SIDH = %00000000 'Set Receive filter 1 bits
    RXF1SIDL = %00000000 'Set Receive filter 1 bits

    COMSTAT = 0 'Clear CAN comminication status register.
    CANCON = %00000000 'Select CAN normal mode
    RXB0CON = %00100000 'Receive only valid messages with standard identifier
    PIR3 = 0 'Clear Peripheral interrupt register 3
    PIE3 = %00100001 'Enable selected Peripheral interrupts

    TXERRCNT = 0 'Clear Transmit error counter
    RXERRCNT = 0 'Clear Receive error counter
    'Clear Transmit buffer 0 bytes
    TXB0D0 = 0
    TXB0D1 = 0
    TXB0D2 = 0
    TXB0D3 = 0
    TXB0D4 = 0
    TXB0D5 = 0
    TXB0D6 = 0
    TXB0D7 = 0
    'Clear Transmit buffer 1 bytes
    TXB1D0 = 0
    TXB1D1 = 0
    TXB1D2 = 0
    TXB1D3 = 0
    TXB1D4 = 0
    TXB1D5 = 0
    TXB1D6 = 0
    TXB1D7 = 0
    'Clear Transmit buffer 2 bytes
    TXB2D0 = 0
    TXB2D1 = 0
    TXB2D2 = 0
    TXB2D3 = 0
    TXB2D4 = 0
    TXB2D5 = 0
    TXB2D6 = 0
    TXB2D7 = 0
    'Clear Receive buffer 0 bytes
    RXB0D0 = 0
    RXB0D1 = 0
    RXB0D2 = 0
    RXB0D3 = 0
    RXB0D4 = 0
    RXB0D5 = 0
    RXB0D6 = 0
    RXB0D7 = 0
    'Clear Receive buffer 1 bytes
    RXB1D0 = 0
    RXB1D1 = 0
    RXB1D2 = 0
    RXB1D3 = 0
    RXB1D4 = 0
    RXB1D5 = 0
    RXB1D6 = 0
    RXB1D7 = 0
    'Clear Variables
    TRANSMIT_DATA_0 = 0
    TRANSMIT_DATA_1 = 0
    TRANSMIT_DATA_2 = 0
    TRANSMIT_DATA_3 = 0
    TRANSMIT_DATA_4 = 0
    TRANSMIT_DATA_5 = 0
    TRANSMIT_DATA_6 = 0
    TRANSMIT_DATA_7 = 0

    NODE_1_DATA_0 = 0 'Clear Variables
    NODE_1_DATA_1 = 0
    NODE_1_DATA_2 = 0
    NODE_1_DATA_3 = 0
    NODE_1_DATA_4 = 0
    NODE_1_DATA_5 = 0
    NODE_1_DATA_6 = 0
    NODE_1_DATA_7 = 0

    NODE_2_DATA_0 = 0 'Clear Variables
    NODE_2_DATA_1 = 0
    NODE_2_DATA_2 = 0
    NODE_2_DATA_3 = 0
    NODE_2_DATA_4 = 0
    NODE_2_DATA_5 = 0
    NODE_2_DATA_6 = 0
    NODE_2_DATA_7 = 0

    NODE_3_DATA_0 = 0 'Clear Variables
    NODE_3_DATA_1 = 0
    NODE_3_DATA_2 = 0
    NODE_3_DATA_3 = 0
    NODE_3_DATA_4 = 0
    NODE_3_DATA_5 = 0
    NODE_3_DATA_6 = 0
    NODE_3_DATA_7 = 0

    NODE_4_DATA_0 = 0 'Clear Variables
    NODE_4_DATA_1 = 0
    NODE_4_DATA_2 = 0
    NODE_4_DATA_3 = 0
    NODE_4_DATA_4 = 0
    NODE_4_DATA_5 = 0
    NODE_4_DATA_6 = 0
    NODE_4_DATA_7 = 0

    RX_NODE_NR = 0

    'Display Setup for my PIC-DIP40 board
    Declare LCD_Interface = 4
    Declare LCD_DTPin = LATD.4
    Declare LCD_RSPin = PORTE.0
    Declare LCD_RWPin = PORTE.1
    Declare LCD_ENPin = PORTE.2
    Declare LCD_Lines = 4
    DelayMS 200
    Cls
    DelayMS 100
    Return
    '************************************************* ************************************************** ***********
    'MCP23017 PORT EXPANDER ROUTINES
    '************************************************* ************************************************** ***********
    MCP23017_INIT:
    HBStart
    HBusOut MCPWRITE, IOCON, [%00111010] 'SET UP THE IOCON REGISTER
    HBusOut MCPWRITE, IODIRA, [%00000000] 'MAKE PORTA ALL OUTPUTS
    HBusOut MCPWRITE, IODIRB, [%00000000] 'MAKE PORTB3-7 OUTPUTS
    HBStop
    Return
    ALL_OUTPUTS_OFF:
    HBStart
    HBusOut MCPWRITE, OLATA, [%00000000]
    HBusOut MCPWRITE, OLATB, [%00000000]
    HBStop
    Return
    WRITE_MCP:
    HBStart
    HBusOut MCPWRITE, OLATA, [PORTEXPA]
    HBusOut MCPWRITE, OLATB, [PORTEXPB]
    HBStop
    Return
    RESET_RELAY: 'PORT GPB.6
    HBStart
    HBusOut MCPWRITE, OLATB, [%01000000]
    DelayMS 200
    HBusOut MCPWRITE, OLATB, [%00000000]
    HBStop
    Return

    'If the program has got to here then the node address has not been read properly (1 - 7)
    'Put message on screen and Flash LED, halt program.


    NODE_ERROR:
    Cls 'Clear screen
    Print At 1,1, "NODE ERROR - ",Dec TX_NODE_NR
    Print At 3,1, "RXEERCNT = ", Dec3 RXERRCNT
    Print At 4,1, "TXERRCNT = ", Dec3 TXERRCNT
    Toggle ErrorLed 'Flash RED LED for Node address error
    DelayMS 1000
    GoTo NODE_ERROR
    Stop

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Prolific Poster rcurl's Avatar
    Join Date
    Mar 2002
    Posts
    1,895
    Thumbs Up
    Received: 32
    Given: 58
    Total Downloaded
    2.38 GB

    0 Not allowed!

    Default Re: 18F4580 CAN Bus & HBUSOUT

    Hi Bob-
    I had a similar problem and it went away when I moved all of the subroutines to the top of the code and then jumped over them. I don't see the main loop in the snippet you posted so I can't really tell if you've got it set up that way or not.

    -Rick

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,374
    Thumbs Up
    Received: 87
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: 18F4580 CAN Bus & HBUSOUT

    even though I don't call it
    You may not call it but you do conditionally goto it.
    IF CAN_Err_Flag = 1 Then GoTo NODE_ERROR
    George.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,942
    Thumbs Up
    Received: 26
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default Re: 18F4580 CAN Bus & HBUSOUT

    Quote Originally Posted by towlerg View Post
    You may not call it but you do conditionally goto it.
    Thanks Rick, I will give that a go. I did try just moving the I2C subroutine to the top, but that made no difference. I will try putting them all up top though.

    Hi George, that line is ok. The problem is with the I2C subroutine. It is not called in the program, but causes a node error

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,390
    Thumbs Up
    Received: 30
    Given: 7
    Total Downloaded
    1.16 GB

    0 Not allowed!

    Default Re: 18F4580 CAN Bus & HBUSOUT

    Hi John,
    I haven't got time to look at your code but just a thought, the I2C is not calling an interrupt which the routine does not handle?

    Bob

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,942
    Thumbs Up
    Received: 26
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default Re: 18F4580 CAN Bus & HBUSOUT

    Thank you all for your replies. I swapped out the pic for another reason and it is working now. Bizarre!

    I've managed to get a node working with a ISO1050 isolated CAN transceiver Bob. Originally I bought some ISO1050 eval boards, but couldn't get them working, so I resorted to soldering SOIC transceivers onto veroboard and it worked first time.

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,390
    Thumbs Up
    Received: 30
    Given: 7
    Total Downloaded
    1.16 GB

    0 Not allowed!

    Default Re: 18F4580 CAN Bus & HBUSOUT

    Hi John,
    I take it you connected the 2nd VCC/VDD for the isolated side, if not I don't think they will work.

    As for the original problem, it may well be the ZIF sockets you have (if you had them on that board), I had loads of issues with mine and doubted my code, in the end got rid on them all and soldered standard rolled pin sockets. All (unexplained) unreliability issues seem to be resolved.

    Bob
    Last edited by RGV250; 5th December 2017 at 21:28.

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Shift Register & Eeprom on same SPI bus
    By pic-ignorant in forum The Lounge
    Replies: 2
    Last Post: 9th February 2015, 07:37
  2. 18F4580 Port A problems
    By SimonGie in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 22nd February 2011, 09:13
  3. SD card SD Bus vs SPI bus
    By normnet in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 25th March 2009, 00:55
  4. Bus I2C HBUSOUT problem
    By gtv_pic in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 13th August 2008, 11:35
  5. 18F4580 port D fun and games
    By Maverick in forum Proton Plus Compiler v3
    Replies: 12
    Last Post: 19th May 2006, 18:31

Tags for this Thread

Posting Permissions

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