Issues sending and receiving data


+ Reply to Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Jul 2024
    Posts
    14

    Default Issues sending and receiving data

    Hi guys,

    I'm trying to send/receive data between 2 PICs on the same circuit.
    The first one (16F1508) is sending data with debug command.

    Code:
    INCLUDE "modedefs.bas" 
    
    DEFINE DEBUG_REG PORTA             ' Set Debug pin port
    DEFINE DEBUG_BIT 2                ' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400            ' Set Debug baud rate 
    DEFINE DEBUG_MODE 0                ' Set Debug mode: 0 = true, 1 = inverted
    
    
    PreAmble     CON     $A5
    
    
    debug PreAmble,$af,$c2,$b5,$ef,13,10
    The second one (16F1503) is receiving the data with debugin command.

    Code:
    INCLUDE "modedefs.bas" 
    
    DEFINE DEBUG_REG PORTC             ' Set Debug pin port
    DEFINE DEBUG_BIT 2                ' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400            ' Set Debug baud rate 
    DEFINE DEBUG_MODE 0                ' Set Debug mode: 0 = true, 1 = inverted
    
    
    DEFINE DEBUGIN_REG PORTA        ' Set Debugin pin port 
    DEFINE DEBUGIN_BIT 1            ' Set Debugin pin bit  
    DEFINE DEBUGIN_BAUD 2400        ' Set Debugin baud rate (same as Debug baud) 
    DEFINE DEBUGIN_MODE 0            ' Set Debugin mode: 0 = true, 1 = inverted 
    
    
    Main:
    DEBUGIN 1000,timeoutlabel,[WAIT("$af"),DAT1,DAT2,DAT3]
    pause 3000
    
    IF DAT1=$c2 THEN
    GOTO SELECTION
    ENDIF
    
    
    
    goto main
    
    
    timeoutlabel:
    debug DEC 99,DAT1,DAT2,DAT3,13,10
    pause 3000
    
    
    goto main
    The data validation fails and the code jumps to the timeout label.

    The timeout label is sending the received information out for troubleshooting purposes.
    For troubleshooting I'm using a Microchip Pickit serial analyzer.

    The information sent is different from the information received.

    This is the data sent from PIC #1 and captured with the analyzer:

    Code:
    [00][A5][AF][C2][B5][EF][0D][0A]
    And this is the data sent from PIC #2 (when in timeoutlabel) and captured with the analyzer:

    Code:
     [4E][4E][BF][79][0D][0A][00]
    Why is the data different? The only data that seems to be correct are the carriage return bytes.
    What am I doing wrong?

    Thanks
    Last edited by PaulMaker; - 28th October 2024 at 20:39.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    I do not see a loop in the sending device. Seems it sends the data once and then stops.

    So the receiving device, if fails to receive first time correct data, loops in the timeout sub.

    Then spits out the data that are randomly stored in the variables, since you do not have a CLEAR command on the top of your program. CLEAR will ensure all variables are set to zero.

    The PAUSE 3000 are not needed I guess, since you have a 1 sec timeout.

    Ioannis.

  3. #3
    Join Date
    Jul 2024
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings Ioannis,

    thank you so much for your help.

    The sending device is actually running on a loop to troubleshoot the issue. I failed to copy that in here but it's something like this:

    Code:
    main:
    
    debug PreAmble,$af,$c2,$b5,$ef,13,10
    
    
    pause 3000
    
    
    goto main
    The receiving pic is also on a loop and that's the reason for the pause 3000 before going back to Main.

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


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    You also have to disable the analog inputs of port A, set by default on PIC reset, by clearing the ANSELA register.

    If you drive the output as in the sender program, then the port is set as digital output. Still I would disable the analog function. But as input it will operate as Analog input, not digital.

    Also get rid of the PAUSE 3000. They offer nothing really useful.

    Ioannis

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    ...... [WAIT("$af"),DAT1,DAT2,DAT3]........ [WAIT($af),DAT1,DAT2,DAT3]

  6. #6
    Join Date
    Jul 2024
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings all,

    thanks for the replies.

    Regarding the I/O setup, I have included the "INCLUDE "ALLDIGITAL.pbp"" on both receiver and sender codes.

    And even with the "[WAIT($af),DAT1,DAT2,DAT3]" modification, I still get the wrong data on the receiver PIC.

    Any additional thoughts?

    Thank you so much.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,514


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Quote Originally Posted by PaulMaker View Post
    Any additional thoughts?
    my thoughts-
    code snippets are a waste of time, a minimal, complete and verifiable example MCVE gets results
    https://stackoverflow.com/help/minim...ucible-example
    Last edited by richard; - 29th October 2024 at 12:05.
    Warning I'm not a teacher

  8. #8
    Join Date
    Jul 2024
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings Richard,

    that makes total sense, sorry for that.

    Here is the code being used to test/troubleshoot the issue...

    The sending PIC triggers COM pin high/low before sending the data.
    The receiving PIC detects the COM trigger with IOC interrupt and starts listening.
    This part of the code is working since it's detecting the trigger and starts listening.
    The thing that is not working is the data reception correctly.

    Send pic code
    Code:
    '****************************************************************'*  Name    : 16F1508_Send.PBP                                  *
    '*            PORTA.2 CONNECTED TO PORTA.1 ON RECEIVING PIC     *
    '****************************************************************
    '
    ;----[16F1508 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1508"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is digital input
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    cfg1&= _IESO_OFF              ; Internal/External Switchover Mode is disabled
    cfg1&= _FCMEN_OFF             ; Fail-Safe Clock Monitor is disabled
      __CONFIG _CONFIG1, cfg1
    
    
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _STVREN_OFF            ; Stack Overflow or Underflow will not cause a Reset
    cfg2&= _BORV_LO               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    cfg2&= _LPBOR_OFF             ; Low-Power BOR is disabled
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    
    
    #ENDCONFIG
    
    
    #ENDIF
    
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #
    
    
    
    
    DEFINE OSC 16                               ' Let PBP clock speed will be 16MHz
    OSCCON = %01111011                          ' Use internal oscillator and set to 16MHz
    
    
    OPTION_REG.7 = 0                            ' Enable individual control of weak pull-ups
    WPUA.0 = 0                                  ' Disable weak pull-up on RA0
    WPUA.1 = 0                                  ' Disable weak pull-up on RA1
    WPUA.2 = 0                                  ' Disable weak pull-up on RA2
    WPUA.3 = 0                                  ' Disable weak pull-up on RA3
    WPUA.4 = 1                                  ' Enable weak pull-up on RA4
    WPUA.5 = 1                                  ' Enable weak pull-up on RA5
    
    
    DACCON0.7 = 0                               ' Disable DAC
    CM1CON0.7 = 0                               ' Disable comparator 1
    CM2CON0.7 = 0                               ' Disable comparator 2
    
    
    TRISA = %00000000                          
    TRISB = %00000000 
    TRISC = %00000000      
    
    
    '*****************************************************************************
    
    
    INCLUDE "ALLDIGITAL.pbp"
    DEFINE SHOWDIGITAL 1
    
    
    INCLUDE "modedefs.bas" 
    
    
    DEFINE DEBUG_REG PORTA 			' Set Debug pin port
    DEFINE DEBUG_BIT 2				' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400			' Set Debug baud rate 
    DEFINE DEBUG_MODE 0				' Set Debug mode: 0 = true, 1 = inverted
    
    
    '*****************************************************************************
    'PORTS & PINS 
    
    
    COMMTX	    	VAR		PORTA.2	
    MESLED	    	VAR		PORTB.5		'MESSAGE LED
    
    
    PreAmble 		CON 	$A5    
    
    
    '*****************************************************************************
    INIT:
    
    
    PORTA=%00000000
    PORTB=%00000000
    PORTC=%00000000
    
    
    GOTO START
    
    
    '*****************************************************************************
    START:
    
    
    HIGH INTLED
    HIGH COMMTX
    PAUSE 500
    LOW COMMTX
    LOW INTLED
    
    
    PAUSE 200
    
    
    HIGH MESLED
    
    
    debug PreAmble,$af,$c2,$b5,$ef,13,10
    
    
    PAUSE 500
    LOW MESLED
    
    
    PAUSE 4000
    
    
    GOTO START
    
    
    '------------------------------------------------------------------------------

    Receive pic code
    Code:
    '****************************************************************'*  Name    : 16F1503_Receive.PBP                               *
    '*            PORTA.1 CONNECTED TO PORTA.2 ON SENDING PIC       *
    '****************************************************************
    '
    ;----[16F1503 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1503"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is digital input
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
      __CONFIG _CONFIG1, cfg1
    
    
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _STVREN_OFF            ; Stack Overflow or Underflow will not cause a Reset
    cfg2&= _BORV_LO               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    cfg2&= _LPBOR_OFF             ; Low-Power BOR is disabled
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    
    
    #ENDCONFIG
    
    
    #ENDIF
    
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    
    '*****************************************************************************
    
    
    DEFINE OSC 16                               ' Let PBP clock speed will be 16MHz
    OSCCON = %01111011                          ' Use internal oscillator and set to 16MHz
    
    
    OPTION_REG.7 = 0                            ' Enable individual control of weak pull-ups
    WPUA.0 = 0                                  ' Disable weak pull-up on RA0
    WPUA.1 = 0                                  ' Disable weak pull-up on RA1
    WPUA.2 = 0                                  ' Disable weak pull-up on RA2
    WPUA.3 = 0                                  ' Disable weak pull-up on RA3
    WPUA.4 = 0                                  ' Disable weak pull-up on RA4
    WPUA.5 = 0                                  ' Disable weak pull-up on RA5
    
    
    DACCON0.7 = 0                               ' Disable DAC
    CM1CON0.7 = 0                               ' Disable comparator 1
    CM2CON0.7 = 0                               ' Disable comparator 2
    
    
    TRISA = %00001010                           ' Set RA1-RA3 as inputs
    TRISC = %00000000                           ' Set RC port as output
    
    
    '*****************************************************************************
    
    
    INCLUDE "ALLDIGITAL.pbp"
    DEFINE SHOWDIGITAL 1
    
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    
    INCLUDE "modedefs.bas" 
    
    
    DEFINE DEBUG_REG PORTA 			' Set Debug pin port
    DEFINE DEBUG_BIT 3				' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400			' Set Debug baud rate 
    DEFINE DEBUG_MODE 0				' Set Debug mode: 0 = true, 1 = inverted
    
    
    DEFINE DEBUGIN_REG PORTA		' Set Debugin pin port 
    DEFINE DEBUGIN_BIT 1			' Set Debugin pin bit  
    DEFINE DEBUGIN_BAUD 2400		' Set Debugin baud rate (same as Debug baud) 
    DEFINE DEBUGIN_MODE 0			' Set Debugin mode: 0 = true, 1 = inverted  
    
    
    '*****************************************************************************
    ;____[ For 12F/16F only - Interrupt Context save locations]_________________
    ;-- Place a copy of these variables in your Main program -------------------
    ;--   The compiler will tell you which lines to un-comment                --
    ;--   Do Not un-comment these lines                                       --
    ;---------------------------------------------------------------------------
    ;wsave   VAR BYTE    $20     SYSTEM      ' location for W if in bank0
    ;wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
                                             ' if using $70, comment wsave1-3
    
    
    ' --- IF any of these three lines cause an error ?? ------------------------
    '       Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using -- 
    ;wsave1  VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    ;wsave2  VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    ;wsave3  VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
    ' --------------------------------------------------------------------------
    'https://www.picbasic.co.uk/forum/showthread.php/3251-Instant-Interrupts-Revisited/page7?highlight=DT%27s+instant+interrupts
    'https://www.picbasic.co.uk/forum/showthread.php/3251-Instant-Interrupts-Revisited/page16?highlight=DT%27s+instant+interrupts
    'Open the DT_INTS-14.bas file and comment out the wsave lines. 
    'The 675 doesn't have any usable RAM in banks 1,2 or 3
    
    
    '*****************************************************************************
    
    
    INTCON.3=1
    IOCAP.1=1 	     'POSITIVE EDGE @ A1 ON
    IOCAN=%0		 'NEGATIVE EDGE OFF
    
    
    'page 106
    
    
    '*****************************************************************************
    '---[INT - interrupt handler]---------------------------------------------------
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler  IOC_INT,    _IOCinterrupts,    PBP,  yes
    endm
    INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    @ INT_ENABLE IOC_INT
    
    
    '*****************************************************************************
    'PORTS & PINS 
    	
    INTLED	    VAR		PORTC.3		'INTERRUPT LED		
    MESLED	    VAR		PORTC.4		'MESSAGE LED
    
    
    '*****************************************************************************
    
    
    DAT1        VAR     BYTE	'
    DAT2        VAR     BYTE	'
    DAT3        VAR     BYTE	'
    CT			VAR		BYTE	'
    
    
    '*****************************************************************************
    INIT:
    
    
    PORTC=%000000
    
    
    GOTO START
    
    
    '------------------------------------------------------------------------------
    START:
    
    
    LOW INTLED
    LOW MESLED
    
    
    GOTO START
    
    
    '------------------------------------------------------------------------------
    IOCinterrupts:
    
    
    @   INT_DISABLE IOC_INT 
    
    
    HIGH INTLED
    
    
    PAUSE 500
    
    
    DEBUGIN 1000,timeoutlabel,[WAIT($af),DAT1,DAT2,DAT3]
    
    
    PAUSE 200
    
    
    pause 500
    
    
    low INTLED
    
    
    PAUSE 500
    
    
    IF DAT1=$c2 THEN
    GOTO PROGSEL
    ENDIF
    
    
    'RETURN TO PROGRAM
    IOCAF=%0
    @ INT_ENABLE IOC_INT
    @ INT_RETURN
    
    
    ;-------------------------------------------------------------------------------
    timeoutlabel:
    
    
    low INTLED
    
    
    HIGH MESLED
    debug DEC 99,DAT1,DAT2,DAT3,13,10 'Message confirming bad reception
    
    
    pause 1000
    low MESLED
    
    
    'RETURN TO PROGRAM
    IOCAF=%0
    @ INT_ENABLE IOC_INT
    @ INT_RETURN
    
    
    ;-------------------------------------------------------------------------------
    PROGSEL
    
    
    debug DEC 09,DAT1,DAT2,DAT3,13,10 'Message confirming reception
    
    
    for ct=0 to 10
    toggle INTLED
    toggle MESLED
    pause 500
    next ct
    
    
    
    
    'RETURN TO PROGRAM
    IOCAF=%0
    @ INT_ENABLE IOC_INT
    @ INT_RETURN
    ;-------------------------------------------------------------------------------
    Thanks for the help

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    .... also maybe.....
    PreAmble CON $A5
    debug PreAmble,$af,$c2,$b5,$ef,13,10
    PreAmble CON $A5


    ,$af,$c2,$b5,$ef,13,10 is equal to 175,194,181,239,13,10 .... so ... debug 165,175,194,181,239,13,10.... or debug HEX 165,175,194,181,239,13,10

    then.... Main:
    DEBUGIN 1000,timeoutlabel,[WAIT(165),DAT1,DAT2,DAT3]
    pause 3000
    or
    Main:
    DEBUGIN 1000,timeoutlabel,[WAIT(HEX $AF),$DAT1,$DAT2,$DAT3]
    pause 3000....
    have to know what exactly characters are sending and receiving... I would output to a serial terminal to see if what you are sending is what you think you are sending
    Last edited by amgen; - 29th October 2024 at 12:47.

  10. #10
    Join Date
    Jul 2024
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings amgen,

    thanks for the help,

    This is the data sent from PIC #1 and captured with the analyzer:


    Code:
    
    
    Code:
    [00][A5][AF][C2][B5][EF][0D][0A]
    



    And this is the data sent from PIC #2 (when in timeoutlabel) and captured with the analyzer:


    Code:
    
     [4E][4E][BF][79][0D][0A][00]
    


  11. #11


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    your sending capture looks good. Handling the receive, the debug in may or may not filter how you want... play with that some because if receiving HEX, that is 2 bytes to make into 1 byte value of DAT etc... ???? ... can also dictate (if it is not the default) 2 digits for the hex... HEX2
    maybe.... DEBUGIN 1000,timeoutlabel,[WAIT("AF"),$DAT1,$DAT2,$DAT3].... or DEBUGIN 1000,timeoutlabel,[WAIT(HEX2 AF),$DAT1,$DAT2,$DAT3].... or DEBUGIN 1000,timeoutlabel,[WAIT(HEX2 "AF"),$DAT1,$DAT2,$DAT3]
    .
    .
    . Thought of 1 more thing.... add a temporary serout or debug and send to your capture or ser terminal 1 received character at a time to easily see what you are receiving
    Last edited by amgen; - 29th October 2024 at 15:08.

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    I do not have that chip, so can you check if this code works please?

    Code:
    '****************************************************************'*  Name    : 16F1503_Receive.PBP                               *
    '*            PORTA.1 CONNECTED TO PORTA.2 ON SENDING PIC       *
    '****************************************************************
    '
    ;----[16F1503 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1503"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is digital input
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
      __CONFIG _CONFIG1, cfg1
    
    
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _STVREN_OFF            ; Stack Overflow or Underflow will not cause a Reset
    cfg2&= _BORV_LO               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    cfg2&= _LPBOR_OFF             ; Low-Power BOR is disabled
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    
    
    #ENDCONFIG
    
    
    #ENDIF
    
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    
    '*****************************************************************************
    
    
    DEFINE OSC 16                               ' Let PBP clock speed will be 16MHz
    OSCCON = %01111011                          ' Use internal oscillator and set to 16MHz
    
    
    OPTION_REG.7 = 0                            ' Enable individual control of weak pull-ups
    WPUA.0 = 0                                  ' Disable weak pull-up on RA0
    WPUA.1 = 0                                  ' Disable weak pull-up on RA1
    WPUA.2 = 0                                  ' Disable weak pull-up on RA2
    WPUA.3 = 0                                  ' Disable weak pull-up on RA3
    WPUA.4 = 0                                  ' Disable weak pull-up on RA4
    WPUA.5 = 0                                  ' Disable weak pull-up on RA5
    
    
    DACCON0.7 = 0                               ' Disable DAC
    CM1CON0.7 = 0                               ' Disable comparator 1
    CM2CON0.7 = 0                               ' Disable comparator 2
    
    
    TRISA = %00001010                           ' Set RA1-RA3 as inputs
    TRISC = %00000000                           ' Set RC port as output
    
    
    '*****************************************************************************
    
    
    INCLUDE "ALLDIGITAL.pbp"
    DEFINE SHOWDIGITAL 1
    
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    
    INCLUDE "modedefs.bas" 
    
    
    DEFINE DEBUG_REG PORTA 			' Set Debug pin port
    DEFINE DEBUG_BIT 3				' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400			' Set Debug baud rate 
    DEFINE DEBUG_MODE 0				' Set Debug mode: 0 = true, 1 = inverted
    
    
    DEFINE DEBUGIN_REG PORTA		' Set Debugin pin port 
    DEFINE DEBUGIN_BIT 1			' Set Debugin pin bit  
    DEFINE DEBUGIN_BAUD 2400		' Set Debugin baud rate (same as Debug baud) 
    DEFINE DEBUGIN_MODE 0			' Set Debugin mode: 0 = true, 1 = inverted  
    
    
    '*****************************************************************************
    ;____[ For 12F/16F only - Interrupt Context save locations]_________________
    ;-- Place a copy of these variables in your Main program -------------------
    ;--   The compiler will tell you which lines to un-comment                --
    ;--   Do Not un-comment these lines                                       --
    ;---------------------------------------------------------------------------
    ;wsave   VAR BYTE    $20     SYSTEM      ' location for W if in bank0
    ;wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
                                             ' if using $70, comment wsave1-3
    
    
    ' --- IF any of these three lines cause an error ?? ------------------------
    '       Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using -- 
    ;wsave1  VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    ;wsave2  VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    ;wsave3  VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
    ' --------------------------------------------------------------------------
    'https://www.picbasic.co.uk/forum/showthread.php/3251-Instant-Interrupts-Revisited/page7?highlight=DT%27s+instant+interrupts
    'https://www.picbasic.co.uk/forum/showthread.php/3251-Instant-Interrupts-Revisited/page16?highlight=DT%27s+instant+interrupts
    'Open the DT_INTS-14.bas file and comment out the wsave lines. 
    'The 675 doesn't have any usable RAM in banks 1,2 or 3
    
    
    '*****************************************************************************
    
    
    INTCON.3=1
    IOCAP.1=1 	     'POSITIVE EDGE @ A1 ON
    IOCAN=%0		 'NEGATIVE EDGE OFF
    
    
    'page 106
    
    
    '*****************************************************************************
    '---[INT - interrupt handler]---------------------------------------------------
    'ASM
    'INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
    '        INT_Handler  IOC_INT,    _IOCinterrupts,    PBP,  yes
    'endm
    'INT_CREATE               ; Creates the interrupt processor
    'ENDASM
    '
    '
    '@ INT_ENABLE IOC_INT
    
    
    '*****************************************************************************
    'PORTS & PINS 
    	
    INTLED	    VAR		PORTC.3		'INTERRUPT LED		
    MESLED	    VAR		PORTC.4		'MESSAGE LED
    
    
    '*****************************************************************************
    
    
    DAT1        VAR     BYTE	'
    DAT2        VAR     BYTE	'
    DAT3        VAR     BYTE	'
    CT			VAR		BYTE	'
    
    
    '*****************************************************************************
    INIT:
    
    
    PORTC=%000000
    
    
    GOTO START
    
    
    '------------------------------------------------------------------------------
    START:
    
    
    LOW INTLED
    LOW MESLED
    
    DEBUGIN 1000,timeoutlabel,[WAIT($af),DAT1,DAT2,DAT3]
    
    GOTO START
    
    timeoutlabel:
        low INTLED
    
    
        HIGH MESLED
        debug "Bad data",13,10 'Message confirming bad reception
    
        pause 1000
        low MESLED
    goto START
    
    
    ''------------------------------------------------------------------------------
    'IOCinterrupts:
    
    
    '@   INT_DISABLE IOC_INT 
    
    
    'HIGH INTLED
    
    
    'PAUSE 500
    
    
    'DEBUGIN 1000,timeoutlabel,[WAIT($af),DAT1,DAT2,DAT3]
    
    
    'PAUSE 200
    
    
    'pause 500
    
    
    'low INTLED
    
    
    'PAUSE 500
    
    
    'IF DAT1=$c2 THEN
    'GOTO PROGSEL
    'ENDIF
    
    
    ''RETURN TO PROGRAM
    'IOCAF=%0
    '@ INT_ENABLE IOC_INT
    '@ INT_RETURN
    
    
    ';-------------------------------------------------------------------------------
    'timeoutlabel:
    
    
    'low INTLED
    
    
    'HIGH MESLED
    'debug DEC 99,DAT1,DAT2,DAT3,13,10 'Message confirming bad reception
    
    
    'pause 1000
    'low MESLED
    
    
    ''RETURN TO PROGRAM
    'IOCAF=%0
    '@ INT_ENABLE IOC_INT
    '@ INT_RETURN
    
    
    ;-------------------------------------------------------------------------------
    PROGSEL
    
    
    debug DEC 09,DAT1,DAT2,DAT3,13,10 'Message confirming reception
    
    
    for ct=0 to 10
    toggle INTLED
    toggle MESLED
    pause 500
    next ct
    
    
    
    
    'RETURN TO PROGRAM
    'IOCAF=%0
    '@ INT_ENABLE IOC_INT
    '@ INT_RETURN
    ;-------------------------------------------------------------------------------
    Ioannis

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,514


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    i don't see this working , porta.3 is input only

    Receive pic code
    Code:
    DEFINE DEBUG_REG PORTA 			' Set Debug pin port
    DEFINE DEBUG_BIT 3				' Set Debug pin bit
    DEFINE DEBUG_BAUD 2400			' Set Debug baud rate 
    DEFINE DEBUG_MODE 0				' Set Debug mode: 0 = true, 1 = inverted

    the concept of reading a serial transmission in an interrupt routine triggered by the start bit is badly flawed.
    by the time the isr's bit-banged reception routine is activated the start bit has been lost and you will just read in a bunch of framing errors
    Warning I'm not a teacher

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    2,514


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    hard to see the red bits doing anything of value except to cause framing errors

    you could add the blue bits to prevent framing errors @ startup

    Code:
    COMMTX            VAR        PORTA.2    MESLED            VAR        PORTB.5        'MESSAGE LED
    
    
    
    
    PreAmble         CON     $A5    
    
    
    
    
    '*****************************************************************************
    INIT:
    
    
    
    
    PORTA=000000
    PORTB=000000
    PORTC=000000
    HIGH COMMTX
    pause 10
    GOTO START
    
    
    
    
    '*****************************************************************************
    START:
    
    
    
    
    HIGH INTLED
    HIGH COMMTX
    PAUSE 500
    LOW COMMTX
    LOW INTLED
    
    
    
    
    PAUSE 200
    
    
    
    
    HIGH MESLED
    
    
    
    
    debug PreAmble,$af,$c2,$b5,$ef,13,10
    
    
    
    
    PAUSE 500
    LOW MESLED
    
    
    
    
    PAUSE 4000
    
    
    
    
    GOTO START

    if you use a viable pin on the rx unit it for debug will work , its not a way i would recommend
    Last edited by richard; - 30th October 2024 at 07:52.
    Warning I'm not a teacher

  15. #15
    Join Date
    Jul 2024
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings everyone,

    first of all, thank you so much for your help.
    Will try your suggestions tonight and give feedback.

    @Richard, just to explain...the red bits are there only to trigger the IOC on the receiver side so that it knows when it needs to start listening.
    The reason is because the receiver PIC will do a lot of tasks and will only stop to pay attention to the RX pin when the IOC is triggered.
    The IOC and RX pins are defined as the same pin to save an I/O pin on both sender and received PICs.


    Best regards
    Rui

  16. #16
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    If you instist on using ISR for the USART receiver, why not use the USART Interrupt directly? It will not work otherwise as Richard noted.

    Test your circuit and logic of the communication first with no interrupts and then decide what to do next.

    Ioannis

  17. #17
    Join Date
    Jul 2024
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Greetings Ioannis,

    Yes, I know...

    the problem is that, although the TX PIC 16F1508 is equipped with a EUSART module, the receiver PIC 16F1503 is not
    The IOC was a workaround that i came up with to trigger the debugin command on the RX PIC.

    Best regards

  18. #18


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    wow, no hardware usart is serious..... your 1503 has mssp interrupt..... if you can make all that work, you are very skilled indeed !

  19. #19
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,987


    Did you find this post helpful? Yes | No

    Default Re: Issues sending and receiving data

    Then you have to run a fast loop and make sure you won't miss any byte.

    Are you sure you cannot change that 1503?

    Ioannis

Similar Threads

  1. SERIN2 Receiving Wrong Data
    By rsocor01 in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 4th May 2024, 21:31
  2. how to display data receiving from xbee to LCD
    By NURULHAIZA in forum mel PIC BASIC
    Replies: 2
    Last Post: - 19th November 2010, 22:24
  3. Sending/receiving data using Linx modules
    By Goat 403 in forum Serial
    Replies: 3
    Last Post: - 21st May 2009, 14:57
  4. Receiving and Transmitting Serial data at the same time
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th April 2007, 23:00
  5. Receiving data from more than one serial Port
    By PICtron in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th March 2005, 11:20

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