PIC to PIC TX RX and PIC to PC COM RX ..a little help please


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    HSERout "9",DEC 3,$d,$a
    Should be
    HSERout ["9",DEC 3,$d,$a]

    Maybe that is why you are getting the "9"???

    Code:
        RCSTA = $90 ' Enable serial port & continuous receive
        TXSTA = $20 ' Enable transmit, BRGH = 0
        SPBRG = 51  ' 2400 Baud @ 8MHz, 0.17%
    
        DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
        DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
        DEFINE HSER_SPBRG 51  ' 2400 Baud @ 8MHz, 0.17%
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Using DEFINE the part in BOLD is not needed.
    Other than that it looks OK to me...

    For the radios... What modules are you using? Did you read the stuff from Dave Houston, http://davehouston.org/ ?

    There is some disagreement on the forum about the preamble/synch protocol. I think Dave's method is the way to go.
    Dave
    Always wear safety glasses while programming.

  2. #2


    Did you find this post helpful? Yes | No

    Default A small bug somewhere..

    Hi Dave :-)

    As reagrds the 93 compiler picked that one up :-)
    So your code-eyes are working!!

    I have still have that small problem somewhere and can't quite figure out where :-( the 93 issue
    It seems like HSERIN is happy to pass the number 9 into the variable as well, even though thats the number it's supposed to wait for !

    Think it's somewhere in the HSERIN/OUT lines ... and I don't think I can move on to the radio portion unless I find the problem :-(
    Do you think you could please cast your 'code eyes' over my code please.

    Here's the Transmitter code
    Code:
    '*************************************
    'Transmit to PIC 18f4520 serout loop
    '*************************************
     '@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
     
    'Ocsillator selections here
      'OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz
    '        OSCCON = %01110001           'Int CLK 8MHz
    '        ANSEL= %11111111       '$0F = disable A/D converter
    '        option_reg = 7     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
     '       define osc 8        '8MHz
    'END of timer/oscillator defines
    'clear the ports
    
    
    
    OSCCON = %01110001          'Int CLK 8MHz
    ANSEL = %00000000           'All digital
    OPTION_REG.7 = 0            'Weak pull-ups enabled
    
    DEFINE OSC 8                '8MHz
    PORTA=0
    PORTB=0
    PORTC=0
    PORTD=0
    PORTE=0
    'end of port clear
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111    <<   'All pins are outputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10100000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
    'includes begin here
            INCLUDE "modedefs.bas"
            include "c:\pbp\samples\keypad.bas"
    'end of includes
                       
    'variables begin here
            myvar var byte
            datatx var byte
            datarx var byte
            net var byte
    'end of variables
    
       
    'USART defines and register settings begin here     - use for HSERIN/OUT
        RCSTA = $90 ' Enable serial port & continuous receive
        TXSTA = $20 ' Enable transmit, BRGH = 0
        SPBRG = 51  ' 2400 Baud @ 8MHz, 0.17%
    
        DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
        DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
        DEFINE HSER_SPBRG 51  ' 2400 Baud @ 8MHz, 0.17%
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    '   Check port settings PORTC.6 = TX and PORTC.7 = RX
    '   For PIC to PIC TX to RX C.6 to C.7 and visa versa
    '   Don't forget TRISC=%10000000
    'USART defines and register settings end here
    
    'main code begins here     
    LED var PORTd.0   ' Alias PORTD.0 to LED
    
    
        
    loopy:
    high LED '  LED on
            Pause 1000       ' Delay for 1 seconds
    
            
     'HSER starts here
             HSERout ["9",DEC 3,$d,$a]
             'HSERIN [WAIT("9"),DEC NET] << this is the format for the receiver 
     'HSER ends here 
           
             low led 'LED off
             Pause 1000       ' Delay for 1 seconds
             Goto loopy  ' Go back to loop and blink LED forever
            End
    'End of all code

    Here's the receiver code

    Code:
    '**************************************************
    RX from anywhere display on LCD and TX to wherever (PIC 18F4520)
    '***************************************************
    
    'Ocsillator selections here
    'DEFINE OSC 8
    'OSCCON=%01110000
    'or
    'DEFINE OSC 4
    'OSCCON=%01100000
    'OSCTUNE.6 = 0 'PLL Multiplier disabled
    'OSCTUNE.6 = 1 'PLL 4x
    'Ocsillator selections here
            OSCCON = $70            'Int CLK 8MHz
            OSCTUNE.6 = 1           'PLL 4x
            ADCON1= %00001111       '$0F = disable A/D converter
            cmcon   =   7 
            INTCON2.7 = 0     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
            DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111       'All pins are inputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10010000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
                       
    'variables begin here
            A0 var byte
            myvar var byte
            datatx var byte
            datarx var byte
            net var byte
            led var PORTD.0
    'end of variables
    
    'LCD defines begin here   
            DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
            DEFINE LCD_DREG PORTD 	'defines the port where data lines are connected to
            DEFINE LCD_DBIT 4 	'defines the position of data lines for 4-bit interface (0 or 4)
            DEFINE LCD_RSREG PORTD 	'defines the port where RS line is connected to
            DEFINE LCD_RSBIT 2 	'defines the pin where RS line is connected to 
            DEFINE LCD_EREG PORTD 	'defines the port where E line is connected to 
            DEFINE LCD_EBIT 3 	'defines the pin where E line is connected 
            'DEFINE LCD_RWREG 0 	'defines the port where R/W line is connected to (set to 0 if not used)
            'DEFINE LCD_RWBIT 0 	'defines the pin where R/W line is connected to (set to 0 if not used)
            DEFINE LCD_COMMANDUS 2000 	'defines the delay after LCDOUT statement 
            DEFINE LCD_DATAUS 200 		'delay in micro seconds
    'END of LCD DEFINES
    
    'includes begin here
            INCLUDE "modedefs.bas"
            include "c:\pbp\samples\keypad.bas"
    'end of includes
    
    'USART defines and register settings begin here     - use for HSERIN/OUT
    
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 207 ' 2400 Baud @ 32MHz, 0.17%
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 207 ' 2400 Baud @ 32MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    '   Check port settings PORTC.6 = TX and PORTC.7 = RX
    '   For PIC to PIC TX to RX C.6 to C.7 and visa versa
    '   Don't forget TRISC=%10000000
    'USART defines and register settings end here
    
       
    'Main code begins here       
    
         Pause 2000       ' Wait for LCD to startup
            
    test:                                                         
            
         high LED 
        
        'HSER starts here -change or comment these for desired direction RX /TX
     
         HSERIN [WAIT("9"),DEC NET] '<< this is the format for the receiver or if 
        
        '     HSERout "I Recived this number ",DEC NET,$d,$a
        'HSER ends here 
        
        lcdout $fe,1 
        lcdout "starting"  
        lcdout $fe,1
        lcdout "POSTTX hser is ", dec net 'show variable net colelcted by hserin a few lines up
        Pause 1000
        Lcdout $fe,1
        lcdout "rx complete"
        pause 1000
        lcdout $fe,1 'clear lcd screen
        lcdout dec net   'display status of net variable
        pause 3000
    IF net = 3 then 
        lcdout $fe,1 
        LCDOUT "MATCH for ",dec net 'look for the number 3 and display MATCH string
        low LED
        pause 2000
    endif  
        lcdout $fe,1
        lcdout "begin hserout to hyperterminal" 'show beginning of TX to PC com port
        pause 1000
        LOOKUP  net,[0,"123A456B789C*0#D"],net 'use lookup table to diplay proper display in hyperterminal
    
        'serout PORTC.3,T2400,["the key pressed or received value is ",net,10,13]
        HSERout ["I Recived this number ",DEC NET,$d,$a] 'net var value should show in hyperterminal
        lcdout $fe,1
        lcdout "transmission complete"
        pause 1000
        goto test
    end
    As regards the RF modules...
    I have the TWS and RWS ones from Rentron and I have some from Telecontrolli namely the RT5 and RRS3

    Not sure what you are referring to about the davehouston site ?? What exactly should I be looking at ?
    I have communicated with Dave because I was trying to get his TX/RX (which uses pulsein and debug) solution implemented in my project but it seems I can't read the correct pules .. still don't know why :-(

    Kind regards

    Dennis
    Last edited by Dennis; - 29th November 2009 at 18:58.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The Dave Houston page to read, but study his whole site for that matter.
    http://davehouston.org/RFTipsTricks.htm

    If you are using DEFINE to set up the HSER then do not add these lines. That is what the DEFINES are for.
    Code:
     RCSTA = $90 ' Enable serial port & continuous receive
     TXSTA = $20 ' Enable transmit, BRGH = 0
     SPBRG = 51  ' 2400 Baud @ 8MHz, 0.17%
    The 93 thing has me confused at the moment.
    You might try SERIN2/SEROUT2 for giggles while you are playing with this serial stuff...
    Dave
    Always wear safety glasses while programming.

  4. #4


    Did you find this post helpful? Yes | No

    Default Ok... been reading and studying like a bat outta hell..

    Dave ...Thanks a million !

    So while the error prevails ...

    Do you have any code snippets I could try to start testing the RF portion be it SERIN/DEBUG/HSERIN etc.
    Perhaps I will find the error in the code while I am experimenting :-)

    Kind regards

    Dennis

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here is part of something from a past project. The "TRAIN" part is the controversial part. But some how the data slicer needs set up. This is where Houstons site is handy..
    SEND:
    Code:
     
    TRAIN	VAR BYTE
    
    TRAIN=$55
    
    SEROUT PORTC.4,T2400,[TRAIN,TRAIN,TRAIN,TRAIN,TRAIN,9,3]
    RECEIVE:
    Code:
    SERIN PORTC.4,T2400,[9],net
    This is just the basic way, you can make it all more reliable by adding checksums and stuff...but this should get you started.
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default it works ...kinda

    Hi Dave :-)
    How are you ?

    Well the lines you gave me work on the wire ..just like before...so I decided to try the TX/RX RF pair TLP-434 and RLP-434 from Bruce at Rentron.
    And .... it works ...kinda :-)
    Instead of seeing the number 3 (DEC 3) it shows me the number 2 (DEC 2) in MCS serial terminal window.
    oh and it also seems to bypass the if NET=3 statement/test for some reason ..I don't think it ever 'sees' a 3 coming in.
    So now I'm wondering where I have gone wrong :-(

    Here's my receiver code :

    Code:
    '*************************************
    'Keypress display on LCD and TX to wherever
    '*************************************
    
    'Ocsillator selections here
    'DEFINE OSC 8
    'OSCCON=%01110000
    'or
    'DEFINE OSC 4
    'OSCCON=%01100000
    'OSCTUNE.6 = 0 'PLL Multiplier disabled
    'OSCTUNE.6 = 1 'PLL 4x
    'Ocsillator selections here
            OSCCON = $70            'Int CLK 8MHz
            OSCTUNE.6 = 1           'PLL 4x
            ADCON1= %00001111       '$0F = disable A/D converter
            cmcon   =   7 
            INTCON2.7 = 0     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
            DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111       'All pins are inputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10010000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
    'variables begin here
           
            net var byte
            
            led var PORTD.0
    'end of variables
    
    'includes begin here
            INCLUDE "modedefs.bas"
            include "c:\pbp\samples\keypad.bas"
    'end of includes
    
    main:
    high LED 
    'RF SERIN line here
    
         SERIN PORTC.4,T2400,[9],net
         serout PORTC.3,T2400,["the key pressed or received value is ",net,10,13]
          low led
          IF net = 3 then 
           low LED
        serout PORTC.3,T2400,["the key pressed or received value is ", net,10,13]
        pause 100
    endif  
    'LOOKUP  net,[0,"123A456B789C*0#D"],net 'use lookup table to diplay proper display in hyperterminal
    '************************SEROUT TO HYPERTERMINAL
    goto main 
    end
    and the transmitter code
    Code:
    
    '*************************************
    '16F887 Transmit to PIC 18f4520 serout loop
    '*************************************
     '@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
     
    'Ocsillator selections here
      'OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz
    '        OSCCON = %01110001           'Int CLK 8MHz
    '        ANSEL= %11111111       '$0F = disable A/D converter
    '        option_reg = 7     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
     '       define osc 8        '8MHz
    'END of timer/oscillator defines
    'clear the ports
    
    
    
    OSCCON = %01110001          'Int CLK 8MHz
    ANSEL = %00000000           'All digital
    OPTION_REG.7 = 0            'Weak pull-ups enabled
    
    DEFINE OSC 8                '8MHz
    PORTA=0
    PORTB=0
    PORTC=0
    PORTD=0
    PORTE=0
    'end of port clear
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111    <<   'All pins are outputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10100000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
    'includes begin here
            INCLUDE "modedefs.bas"
            include "c:\pbp\samples\keypad.bas"
    'end of includes
                       
    'variables begin here
            
            
            LED var PORTd.0   ' Alias PORTD.0 to LED
     'RF variables
            TRAIN	VAR BYTE
            TRAIN=$55
            net var byte
     'Variables end here
    
        
    loopy:
            high LED '  LED on
            'for RF use the line below
            SEROUT PORTC.4,T2400,[TRAIN,TRAIN,TRAIN,TRAIN,TRAIN,9,3]
            low led
    goto loopy
    end
    Any help would be greatly appreciated

    Kind regards
    Dennis

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Getting a 2 ?? Maybe you just need to add 1

    Try sending something other than a 9 or waiting for something other than a 9.
    It must be seeing the 9 or it would not go on to the next command.

    This is the very most basic code, but it does work. I pulled it from my "laser fence". If the beam is broken the TX kicks in and an alarm goes off at the house.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Direct PIC to PC without MAX232
    By acjacques in forum Serial
    Replies: 14
    Last Post: - 23rd October 2014, 21:32
  2. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 00:52
  3. PIC or xbee times out after Tx 504 bytes
    By archendekta in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd November 2009, 08:45
  4. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  5. RX TX modules - intermitent communication
    By ruijc in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2009, 00:13

Members who have read this thread : 3

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