Issues sending and receiving data


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jul 2024
    Posts
    28


    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

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


    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

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,696


    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

  4. #4
    Join Date
    Jul 2024
    Posts
    28


    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

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

  6. #6
    Join Date
    Jul 2024
    Posts
    28


    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

  7. #7


    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 !

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 : 1

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