Wireless modules - help with code not working


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Hi all, I'm trying the true mode, but my loopback setup is still not working.

    Code:
    '**************************************************************************
    '*Program to test XRF radio communications via loopback method            *
    '*Uses a pushbutton switch on porta pin 4                                 *
    '*Target processor is PIC 12f1822                                         *
    '*207 program words, revised 05/07/2013                                   *
    '*Program by Dick Ivers                                                   *
    '*All rights reserved                                                     *
    '************************************************************************** 
    'set 12f1822 configurat1on
    #CONFIG
      __config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CLKOUTEN_OFF & _WDTE_ON
      __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    #endconfig
    
    'set registers
            OSCCON = %01111000   '16 mhz osc
            OSCTUNE = 0          'factory calibration
            ANSELA = 0           'all digital inputs
            OPTION_REG.7 = 0     'global pullups enabled
            WPUA = %010000       'porta pin 4 weak pullup enabled
            CM1CON0.7 = 0        'comparator disabled
            TRISA  = %011110     'porta.0 & porta.5 are outputs, all others input
    
        while OSCSTAT.0 = 0      'wait for stable freq.
        wend
        
        define OSC 16            '16 mhz oscillator
    
    'Define debug parameters
    DEFINE DEBUG_REGG PORTA        'set debug port to porta
    DEFINE DEBUG_BIT 0             'use pin ra0 of porta for debug
    DEFINE DEBUG_BAUD 9600         'set baud rate to 9600
    DEFINE DEBUG_MODE 0            'communicate in true mode
    
    DEFINE DEBUGIN_REGG PORTA      'set debug port to porta
    DEFINE DEBUGIN_BIT 1           'use pin ra1 of porta for debugin
    DEFINE DEBUGIN_BAUD 9600       'set baud rate to 9600
    DEFINE DEBUGIN_MODE 0          'communicate in true mode
    
        i var byte
        char var byte
    
        For i = 1 to 3
        porta.5 = 0              'led on
        pause 333
        porta.5 = 1              'led off
        pause 333
        next
    
    asleep:
        nap 2   'delay 4 ms
        if porta.4 = 1 then asleep
      
    DT:
        debug 55
        debugin 100,blink,[char]
        if char = 55 then
         porta.5 = 0            'led on solid
         goto halt
        endif    
    
    blink:
        porta.5 = 0     'led
        pause 500
        porta.5 = 1     'led off
        pause 500
        if porta.4 =1 then asleep
        goto DT   
       
    halt:
        stop                   'led stays on
    The communications not working. The led blinks when the remote transceiver is not powered, as it should. When its powered the program should branch to a solid on led , but no it keeps blinking. Any ideas?

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Dick, I would suggest at first to test your code with a PC and see if you have the PIC working. For this you will need a MAX232 or similar to invert and drive the serial port.

    If this test passes please post your results. But I have a feeling that it won't.

    Ioannis

    P.S. Also try with capitals in define OSC 16. As this: DEFINE OSC 16. Just in case...
    Last edited by Ioannis; - 8th May 2013 at 08:22.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Ioannis,
    PIC to PC is working. Code and setup as follows:

    Code:
    '**************************************************************************
    '*Program to test PIC to PC communications via loopback method            *
    '*Target processor is PIC 12f1822                                         *
    '*142 program words, revised 05/08/2013                                   *
    '*Program by Dick Ivers                                                   *
    '*All rights reserved                                                     *
    '************************************************************************** 
    'set 12f1822 configurat1on
    #CONFIG
      __config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CLKOUTEN_OFF & _WDTE_ON
      __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    #endconfig
    
    'set registers
            OSCCON = %01111000   '16 mhz osc
            OSCTUNE = 0          'factory calibration
            ANSELA = 0           'all digital inputs
            OPTION_REG.7 = 0     'global pullups enabled
            WPUA = %010010       'porta pin 1 and pin 4 weak pullups enabled
            CM1CON0.7 = 0        'comparator disabled
            TRISA  = %011110     'porta.0 & porta.5 are outputs, all others input
    
        while OSCSTAT.0 = 0      'wait for stable freq.
        wend
        
        define OSC 16            '16 mhz oscillator
    
    'Define debug parameters 
    DEFINE DEBUG_REGG PORTA        'set debug port to porta
    DEFINE DEBUG_BIT 0             'use pin ra0 of porta for debug
    DEFINE DEBUG_BAUD 9600         'set baud rate to 9600
    DEFINE DEBUG_MODE 1            'communicate in inverted mode
    
    DEFINE DEBUGIN_REGG PORTA      'set debug port to porta
    DEFINE DEBUGIN_BIT 1           'use pin ra1 of porta for debugin
    DEFINE DEBUGIN_BAUD 9600       'set baud rate to 9600
    DEFINE DEBUGIN_MODE 1          'communicate in inverted mode
    
        i var byte
        char var byte
    
        For i = 1 to 3
        porta.5 = 0              'led on
        pause 333
        porta.5 = 1              'led off
        pause 333
        next
    
    'user input with VT100 terminal
    
    re:     debugin [char]     
            debug char
            
            goto re
    The PIC echos back to the PC correctly. Double characters display as expected. Note that the transmission mode is inverted. I believe this mode is standard for RS232 communications. Also, I am using a null modem cable (Tx and Rx reversed ). I believe this is also standard. Haven't tried the radio link yet with this set up.. Any suggestions?
    Dick

    p.s. The DEFINES are capitals in the actual code. Not all show this way with the pasted code.
    Last edited by Dick Ivers; - 8th May 2013 at 18:10.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    I'd type over the DEFINES in capitals. If you copy & paste from your code and they come out in lower case here, then it seems like your IDE is just displaying to you in upper case. They are still lower as far as PBP is concerned.

    Robert

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


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Since PIC to PC is working then I have three thoughts on this.

    1. one or both modules are not working. You may try here to change the modules between them.

    2. Settings are not the defaults

    3. The feeds to the modules are reversed (tx to rx etc).

    The modules need true mode and not the inverse you just tested with the PC. But I suppose you will change your code for this test.

    Wish you luck, cannot see anything else now...

    Ioannis

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Hi all,

    Working at last...... the problem was reversed Tx and Rx, just as Ioannis suggested above. I was misled by incorrect markings on the prototype board I got from Ciseco. Also, I corrected the define caps, although this did not seem to be a problem because the leds were blinking at the right speeds.... thanks for the tip Robert. You guys are very patient to stick through this ... I salute you. Final code here:

    Code:
    '**************************************************************************
    '*Program to test XRF radio communications via loopback method            *
    '*Uses a pushbutton switch on porta pin 4                                 *
    '*Target processor is PIC 12f1822                                         *
    '*207 program words, revised 05/08/2013                                   *
    '*Program by Dick Ivers                                                   *
    '*All rights reserved                                                     *
    '************************************************************************** 
    'set 12f1822 configurat1on
    #CONFIG
      __config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CLKOUTEN_OFF & _WDTE_ON
      __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    #endconfig
    
    'set registers
            OSCCON = %01111000   '16 mhz osc
            OSCTUNE = 0          'factory calibration
            ANSELA = 0           'all digital inputs
            OPTION_REG.7 = 0     'global pullups enabled
            WPUA = %010010       'porta pin 1 and pin 4 weak pullups enabled
            CM1CON0.7 = 0        'comparator disabled
            TRISA  = %011110     'porta.0 & porta.5 are outputs, all others input
    
        while OSCSTAT.0 = 0      'wait for stable freq.
        wend
        
        DEFINE OSC 16            '16 mhz oscillator
    
    
    'Define debug parameters 
    DEFINE DEBUG_REGG PORTA        'set debug port to porta
    DEFINE DEBUG_BIT 0             'use pin ra0 of porta for debug
    DEFINE DEBUG_BAUD 9600         'set baud rate to 9600
    DEFINE DEBUG_MODE 0            'communicate in true mode
    
    DEFINE DEBUGIN_REGG PORTA      'set debug port to porta
    DEFINE DEBUGIN_BIT 1           'use pin ra1 of porta for debugin
    DEFINE DEBUGIN_BAUD 9600       'set baud rate to 9600
    DEFINE DEBUGIN_MODE 0          'communicate in true mode
    
        i var byte
        char var byte
    
        For i = 1 to 3
        porta.5 = 0              'led on
        pause 333
        porta.5 = 1              'led off
        pause 333
        next
    
    asleep:
        nap 2   'delay 4 ms
        if porta.4 = 1 then asleep
     
    DT:
        debug 55
        debugin 100,blink,[char]
        if char = 55 then
         porta.5 = 0            'led on solid
         goto halt
        endif    
    
    blink:
        porta.5 = 0             'led
        pause 500
        porta.5 = 1             'led off
        pause 500
        if porta.4 =1 then asleep
        goto DT   
       
    halt:
        stop                   'led stays on

  7. #7
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Wireless modules - help with code not working

    Congratulations on sorting it Dick.

    I'm having problems with my code which seems so simple but it won't work with serin/out2 qualifiers.

    I have commented out the Serin2 ACK in the control code as it doesn't get one due to the field code not working. This way, at least the code works the relay ok if I remove the Serin2 qualifier and just send "BOB".
    This points to the qualifiers as the culprit as without them the code works OK.

    I've tried every combination and it doesn't respond. All I want in the Field unit is to receive a qualifier to branch to the desired gosub.

    Please bear in mind code below is probably incorrect as it's what's left of trying.

    Control code

    Code:
    Include "modedefs.bas" 
    DEFINE OSC 10
    
    TRISA=%00000000
    TRISB=%11110000
    CMCON=7                  ; comparators off
    
    redled VAR PortB.4
    greenled VAR PortB.5
    yellowled VAR PortB.6
    switch VAR PortB.7
    
    redstop VAR BYTE
    greengo VAR BYTE
    flip VAR BYTE
    
    ;relay var PortA.1
    
    flip = 0         ; counter flipflop for single command send
    
    redstop = 1
    greengo = 2
    
    
    test:            ; test led outputs
          high redled
          pause 500
          low redled
          high greenled
          pause 500
          low greenled
          high yellowled
          pause 500
          low yellowled
          
          pause 2000
          
    main:
    
    IF SWITCH = 1 and flip = 0 THEN GOSUB red
        pause 500
    IF switch = 0 and flip = 1 then gosub green
    
    goto main
    
    red:
        pause 1
        SEROUT2 PortA.3,T9600,["BOB",redstop]       ; send command to field unit
        ;SERIN2 PortA.2,84,[WAIT("ACK")]           ; wait for acknowledge signal
        low greenled
        high redled
        flip = 1                                  ; flip flop counter to ensure send only once
        gosub flash                               ; flash test led
        return  
        
    green:
        pause 1    
        SEROUT2 PortA.3,T9600,["BOB",greengo]  
        ;SERIN2 PortA.2,84,[WAIT("ACK")]
        low redled
        high greenled
        flip = 0
        gosub flash
        return 
        
    flash:
          high yellowled
          pause 50
          low yellowled
          PAUSE 50
          high yellowled
          pause 50
          low yellowled
          PAUSE 50
          high yellowled
          pause 50
          low yellowled
           
        return
        
    END

    Field code

    Code:
    Include "modedefs.bas" 
    DEFINE OSC 10
    
    TRISA=%00000100
    CMCON=7
    
    relay   VAR PortA.1
    
    signal var BYTE
    
    low relay
    
    
    
    ' Program
    MAIN:
        
        SERin2 PortA.2,84,[wait("BOB"),dec SIGNAL]
            
        if signal = 1 then 
        gosub redstop 
        endif
    
        if signal = 2 then
        GOsub greengo
        endif
    
    goto main
        
    
    redstop:
        high relay
        pause 25 
        SEROUT2 PortA.3,T9600,["ACK"] 
        return
    
    greengo:
        low relay
        pause 25
        SEROUT2 PortA.3,T9600,["ACK"] 
        return 
      
    END

    As an oddball I also discovered that FOR NEXT just doesn't seem to work in any of my codes?

    Rob

Similar Threads

  1. Wireless modules and simple setup, what is required?
    By tasmod in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 11th April 2013, 17:57
  2. Low latency Wireless RF transceiver modules?
    By mark155 in forum General
    Replies: 0
    Last Post: - 4th March 2010, 05:20
  3. Wireless modules FCC approved
    By Michael in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th September 2008, 02:23
  4. Software RS232 and wireless modules
    By Michael in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th August 2008, 05:27
  5. Wireless comms with Linx LR modules
    By telemark in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd July 2006, 01:58

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