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


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 68 of 68
  1. #41


    Did you find this post helpful? Yes | No

    Default looping HSER

    Hi Dave

    Have been reading the very interesting HSER info form all over.

    Let's say that I have the PIC's connected as follows :
    PIC 16F887 -- PIC 18F4520 -- PC(com port)

    At PIC 16F887 the code is
    Code:
    '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: 'tx loop begins
    high LED '  LED on
            Pause 1000       ' Delay for 1 seconds
    HSERout "9",DEC 3,$d,$a 
    low LED ' LED off
    pause 1000
    goto main
    On the 18F4520 (middleman RX and TX PIC in my setup)
    Code:
    '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: 'tx and rx loop begins here
    high LED 'LED on 
    Pause 1000 ' delay for 1 second
    'HSER lines begine here
             HSERIN [WAIT("9"),DEC NET] '<< this is the format for the receiver or if you're looping
    LCDOUT $fe,1 
    LCDOUT "I received the number .." DEC NET
    HSERout "I received the number",DEC NET,$d,$a  'data to COM port on pc
    'HSER lines end here
    goto main 
    end
    And on the PC hyperterminal or MCS serial tool is waiting to receive and/or send back to PIC

    Have I got it right ?

    Kind regards

    Dennis

  2. #42


    Did you find this post helpful? Yes | No

    Default suprise suprise .......

    Dave ...........

    IT works :-)

    16F887 runnning @ 8 MHz internal clock
    to 18F4520 running @ 32 MHz internal clock
    to PC com port @ 2400bps 8N1

    and the readout in plain text at MCS serial tool/hyperterminal is...
    I received the number 93
    I received the number 93
    I received the number 93 etc
    :-)
    Not sure why it's not just displaying the number 3 which is what I was expecting ... a bug in the code for HSER lines perhaps ????

    But besides that .....YAY !

    And now for the next mission ....
    RF TX/RX ....

    Only 5 step process for now ( or more LOL depending on the TX/RX protocol,modules and more I guess --wish me luck !)

    1. Wire up RF modules to PIC's
    2. Remove existing TX/RX wires between PIC's ( keep avaiable for tests)
    3. Wire the transmitter PIC's TX to RF TX module
    4. Wire the receiver PIC's RX to RF RX module
    5. Test for comms :-) << hold thumbs

    Any tips would be highly appreciated and noted !

    Kind regards

    Dennis
    Last edited by Dennis; - 29th November 2009 at 14:12.

  3. #43
    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.

  4. #44


    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.

  5. #45
    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.

  6. #46


    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

  7. #47
    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.

  8. #48


    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

  9. #49
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEC net
    Might be the missing link...on the display

    If the LED goes low then I would say it is working, but try sending something else and see what happenes.
    Dave
    Always wear safety glasses while programming.

  11. #51


    Did you find this post helpful? Yes | No

    Default and now for the next step

    Hi Dave

    I still haven't solved the number 3 problem
    Where should I place the DEC keyword in ? As I try to compile with DEC keyword in, MCS spits out compile errors.

    I am using TLP-434 and RLP-434 modules.
    With this in mind would you suggext I now start adding in manchester encoding ?
    Should I be trying SERIN/OUT2, DEBUG and HSER first ? (these all worked well when the PIC's were wired together)

    I see your lines of serin code pre-condition the receiver first, should i be sending more $55's ?

    As always any help or suggestions,tips,tricks etc would be greatly appreciated.

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Well crap. The DEC modifier does not work with straight SERIN. Sorry about that.

    Yes, setup for SERIN2/SEROUT2
    get that working with wires and we will go from there.

    The Manchester stuff is not needed at this time.
    Dave
    Always wear safety glasses while programming.

  13. #53


    Did you find this post helpful? Yes | No

    Default it's working

    Hi Dave

    Great news ;-)

    It's working :-) and I'm thrilled --thank you!

    Using HSERIN both wired and wireless
    WOOOOOHOOOOO!

    Now I have a question...
    I would say the receiver get's maybe one in every 50 sent packets, if I'm lucky ;-(
    What do I need to change or try to make this better ?
    The reason I am asking is because I would like to press button 3 on the keypad and that is transmitted and receiver number 3 switches on.
    Does that make sense ?

    Kind regards

    Dennis

  14. #54
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    I would say the receiver get's maybe one in every 50 sent packets, if I'm lucky ;-(
    You need 2-3m physical separation between TX & RX. Otherwise, the superregenerative receiver and the transmitter will interfere with each other.

  15. #55


    Did you find this post helpful? Yes | No

    Default I have that distance

    Hi Dave Houston

    Thanks million for the reply.

    I have them even farther apart >3m
    If I am closer I receiver more transmitted frames, as I move further so the number decreases.

    I tried the same transmitter and receivers using your code as well but have no success when I use it but it does work when the two PICS are connected by wire !

    I will most certainly try increasing or reducing the range...
    and then update a little later :-)
    I will also try your code using the PIC 12F629's as well

    If you have any more suggestions I would happily try them and submit feedback

    Thanks again

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    I think the modules you are using are the same as Bruce sells, the RWS/TWS ones?
    What are you using for an antenna and how long is it? Should be around 6.5 inches. Ground plane? Anything around that could be causing interference? A picture of the setup might help.

    Can you post the code that is sorta working? At this point it could be a number of things. We have to rule out hardware or software.

    Now try to tighten things up a bit.

    Code:
    TRAIN  VAR BYTE
    train =  $B3
    SYNK VAR BYTE
    SYNK = $7E
    
    SEROUT2 PORT??, BAUD?,[TRAIN, SYNK, DEC 23]
    Code:
    SYNK VAR BYTE
    SYNK = $7E
    MYVAR  VAR BYTE
    
    SERIN2  PORT??, BAUD?, [WAIT(SYNK), DEC MYVAR]
    Dave
    Always wear safety glasses while programming.

  17. #57


    Did you find this post helpful? Yes | No

    Default IT WORKS better than before :-)

    Dave :-)

    It's working like a charm :-)....I think, just getting an

    extra character on every second line :-)
    Range is awesome in the house, reaches all distant corners

    --will do range tests tomorrow and feedback to you.

    Here's the OLD code

    Which worked but wasn't too accurate

    TX CODE
    Code:
    TRAIN	VAR BYTE
    TRAIN=$55
    
    
    hSEROUT [TRAIN,TRAIN,TRAIN,TRAIN,TRAIN,"9",dec 3,$d,$a]
    RX code
    Code:
    HSERIN [WAIT("9"),DEC NET]
    
     HSERout ["I Recived this number ",DEC NET,$d,$a] 'net var 
    
    value should show in hyperterminal
    Heres the NEW TX code
    USING HSER

    Code:
    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
    
    test:
    TRAIN  VAR BYTE
     train =  $B3
     SYNK VAR BYTE
     SYNK = $7E
    
    hserout [TRAIN,SYNK,DEC 23]
    goto test


    and the RX code:

    Code:
    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
    
    test:
    
    high led
    
    hserin [WAIT(SYNK), DEC net]
    
    
    toggle LED
    HSERout ["I Recived this number ",DEC NET,$d,$a] 'net var 
    
    value should show in hyperterminal
    
    goto test


    Here's my receiver output from MCS serial tool window
    Code:
    I Recived this number 2
    I Recived this number 23
    I Recived this number 2
    I Recived this number 23
    I Recived this number 2
    I Recived this number 23
    As you can see I'm receiving DEC 2 and 23.
    Where is the number 2 coming from ?
    Eerie ?

    Now all I need to do is akind of checksum for example, if

    the number 23 is received 3 times then it's a VALID TX.

    Any more optimizations or tweaks I should try ?

    Thanks a million

    Kind regards

    (From a very happy:-))
    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    COOL!!!!

    Probably the easiest thing to do for this app would be a simple check.
    Code:
    hserin [WAIT(SYNK), DEC net]
    IF net = 23 THEN ...
    Or build a checksum... but try the above first, keep it simple.
    Last edited by mackrackit; - 6th December 2009 at 03:38.
    Dave
    Always wear safety glasses while programming.

  19. #59
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Dennis, you should remove the DEC command from the HSEROUT see the code below.


    Code:
    A0 var BYTE
    
    A0=23
    'hserout [TRAIN,SYNK,DEC 23]
    hserout [TRAIN,SYNK, A0]
    Al.
    All progress began with an idea

  20. #60


    Did you find this post helpful? Yes | No

    Default Ok will try :-)

    Hi Al

    How are you?

    Thanks for the tip will definitely try it :-)

    Kind regards

    Dennis

  21. #61
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    I tried the same transmitter and receivers using your code as well but have no success when I use it but it does work when the two PICS are connected by wire !
    If it works wired but not wireless, the most likely explanation is that you have something amiss in the way you have connected the TX/RX modules.

  22. #62


    Did you find this post helpful? Yes | No

    Default uncanny behaviour!!

    Hi Al, Dave and Dave

    This appear to be an HSEROUT issue!!

    When I use HSERIN with a string before the variables like this - check reciver code HSEROUT line
    RECEIVER
    Code:
    'variables begin here
            A0 var byte
            net var byte
            led var PORTD.0
            SYNK VAR BYTE
            SYNK = $7E
    
    'end of variables
    
    test:
    
    hserin [WAIT(SYNK),DEC net]
        
        
        if net = 23 then 
        lcdout "i got 23 "
        toggle LED
        'lcdout $fe,1
        endif
    
     HSERout ["got this",DEC net,$d,$a] 'net var show in hyperterminal 
    
     got test 
    
    end


    TRANSMITTER
    Code:
     'RF variables
     'A0 var BYTE
     'A0=23
      'TRAIN	VAR BYTE
     'TRAIN=$55
     TRAIN  VAR BYTE
     train =  $B3
     SYNK VAR BYTE
     SYNK = $7E
    
     'Variables end here
    
        
    loopy:
    
    high LED '  LED on
    hserout [TRAIN,SYNK,dec 23]
     low led 'LED off
     Goto loopy  ' Go back to loop and blink LED forever
            End
    then the number 23 as well as the number 2 appears !!
    See here:
    Code:
    got this23
    got this2
    got this23
    got this2
    got this23
    got this2
    got this23
    got this2
    got this23
    got this2
    If I remove the string of letters , in this case "got this " then every single received line shows only the number 23 which is what we are expecting to see!
    See here:
    Code:
    23
    23
    23
    23
    23
    3
    23
    23
    23
    23
    23
    23
    PERFECT except for once in a while the occasional number like 2 or 3 shows up!

    And trying Al's suggestion of removing the DEC modifier (only on receiver side and for both hserin and hserout)
    I get this
    Code:
    got this2
    got this2
    got this2
    got this2
    got this2
    got this2
    got this2
    got this2
    Now tell me that's not a strange one


    Now...some really awesome observations from my tests here :

    First off this is working like a charm !
    It's pretty damn close to near perfect in terms of reliable data transfer! (would love any further suggestions re checksums -- I though of something like catching a few instanced of the byte and then accepting it as correct!

    Range is awesome ! Right now, as I am typing this the Transmitter is outside my house at the edge of the property - well over 200m and I have taken it upstairs and downstairs every little nook and cranny and it's still spot on !

    Speed is fantastic - its so fast the led hardly blinks and the MCS serial tool window is filled up in less than a second

    I have both receiver and transmitter hooked up to a 9V battery and then into a 5V regulator with no caps anywhere. My entire house is flooded with 2,4 and 5,8 GHz wireless and there are electrical appliances plentifold.

    If the receiver is left in powered on happily waiting for it's signal , as the transmitter is powered on the receiver has already caught at least 6 bytes :-) ...this is how wireless should be in a perfect world :-)
    I would be happy to report that the combination of train and sync byte are a winner! Spot on Mackrackit - thank you!



    I am extremely happy with verything so far and just want to thank all of you who have guided me with code snippets, corrections and everything else!

    Thank you so much !!

    Dave Houston I will still definitely be getting you code working too, come rain hail or snow!

    All that remain (for now :-)) is the ability to send more than one byte.
    I was thinking 3 bytes. (24 bits total)
    So my question is this:
    Assuming I am to stick with this method , what is the best method (most relaible) to be adding more bytes to be sent ?

    Thanks yet again

    Kind regards

    Dennis

  23. #63
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    ...And trying Al's suggestion of removing the DEC modifier (only on receiver side and for both hserin and hserout)
    Dennis, I suggested you to remove the DEC modifier in Transmitter not in the receiver side.

    The reason is that you Tx a pure ascii code and convert it to decimal at the receiver side, while now you are modifying the byte twice (at Tx & at Rx) and can yield wierd results.

    Al.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Al for pointing out my mistake.

    Dennis,
    Just for fun, send this straight to the terminal, you might find it interesting.
    Code:
    XNUM    VAR BYTE[8]
    XNUM = 225 'CHANGE THIS NUMBER AS NEEDED
    
    SEROUT2 GPIO.5,16780,[TRAIN,SYNK,DEC XNUM.7,DEC XNUM.6,DEC XNUM.5,_
       DEC XNUM.4,DEC XNUM.3,DEC XNUM.2,DEC XNUM.1,DEC XNUM.0,_
       "--",DEC XNUM,$d,$a]
    More bytes?
    SEND
    Code:
        XNUM    VAR BYTE
        YNUM    VAR BYTE
        ZNUM    VAR BYTE
        
        XNUM = 225
        YNUM = 100
        ZNUM = 4
        START:
        SEROUT2 GPIO.5,16780,[TRAIN,SYNK,XNUM,YNUM,ZNUM,$d,$a]
        PAUSE 5000
        GOTO START
    RECEIVE
    Code:
        XNUM    VAR BYTE
        YNUM    VAR BYTE
        ZNUM    VAR BYTE
        
        START:
        SERIN2 GPIO.5, 16780,[WAIT(SYNK),XNUM,YNUM,ZNUM]
        
        SEROUT2 GPIO.4,16780,["X-",DEC XNUM," Y-",DEC YNUM," Z-",DEC ZNUM,$d,$a]
        GOTO START
    Dave
    Always wear safety glasses while programming.

  25. #65


    Did you find this post helpful? Yes | No

    Default ok.... just for fun !

    Al thanks a million for the clarity on that one .. will check and feedback !

    Dave ... ok just for fun so be it !
    And if I get greedy would the Var bytes be num num num ? :-)

    Expect Feedback .. results may vary :-0

    Kind regards

    Dennis

  26. #66


    Did you find this post helpful? Yes | No

    Default working!!

    Hi Dave ;-)

    That TX RX code you passed on works like a charm too X Y and Z coming through clear as day although I changed it for HSERIN and HSEROUT

    Not sure what you want me to try with this code though ??

    [code]
    XNUM VAR BYTE[8]
    XNUM = 225 'CHANGE THIS NUMBER AS NEEDED

    SEROUT2 GPIO.5,16780,[TRAIN,SYNK,DEC XNUM.7,DEC XNUM.6,DEC XNUM.5,_
    DEC XNUM.4,DEC XNUM.3,DEC XNUM.2,DEC XNUM.1,DEC XNUM.0,_
    "--",DEC XNUM,$d,$a]
    [code]

    Did you want me to TX/RX it ? modify and put on send and receive side ?

    Dennis

  27. #67


    Did you find this post helpful? Yes | No

    Thumbs up Mods

    Hi Al

    I applied your suggestion , unfortunately it didn't work , my receiver side has an IF ..THEN statement looking for the number 23, and implementing your suggestion on the TX side only doesn't seem to send the correct DEC 23 to the RX so the IF condition is never met ...check my receiver side code for clarification.
    To confirm , I only left the DEC modifier on the receiver side.. (please note though that at the receiver side I have hserin and hserout statements using the DEC modifier.
    I placed your code suggestion on the TX of the first PIC only ..so it looks something like this
    TX ----------- hyoerterminal
    TX ------RF----- RX
    PIC1 PIC2

    Will bash around with it a little more and see what comes of it :-)
    I'll post result back as soon as I have double checked each step too.

    kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    Hi Dave ;-)

    That TX RX code you passed on works like a charm too X Y and Z coming through clear as day
    Really??? Well how about that...
    Not sure what you want me to try with this code though ??

    [code]
    XNUM VAR BYTE[8]
    XNUM = 225 'CHANGE THIS NUMBER AS NEEDED

    SEROUT2 GPIO.5,16780,[TRAIN,SYNK,DEC XNUM.7,DEC XNUM.6,DEC XNUM.5,_
    DEC XNUM.4,DEC XNUM.3,DEC XNUM.2,DEC XNUM.1,DEC XNUM.0,_
    "--",DEC XNUM,$d,$a]
    [code]

    Did you want me to TX/RX it ? modify and put on send and receive side ?

    Dennis
    Send directly to a terminal.
    You said you wanted three bytes, sometimes 8 bits can be as good. just thought you might see a use... splitting the byte up, multiple outputs on the same port... but if you need 23 then it will not help you this time.

    Al was suggesting you only put the DEC on the RX side. That is why I thanked him for pointing out my mistake. I put a DEC on both in a couple of post.
    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