HC-12 Radio module TX RX in Oshonsoft

Discussion in 'The Projects Forum' started by camerart, Apr 17, 2018.

  1. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    I have a thread on another forum, but so far I haven't been able to get two PIC PCBs with HC-12 radio modules to RECEIVE and switch a LED ON/OFF.

    I have two PCBs each with an HC-12, also a serial input to a computer READing from a 3rd HC-12 onto a Terminal.

    Both PCBs TX and are RXed on the screen ok.

    I've tried to send '0' and '1' as a switch from TX, and the RX shows some results, but not clean LED ON/OFF.

    This is in Oshonsoft.

    Here's the latest TX and RX CODE:
    This gives RLED always ON, YLED sometimes ON/OFF
    I tried many > and < numbers, and found =106 worked 50% of the time for some strange reason?

    Any help please?
    Camerart.

    TX:--------------------------------------------------------------------------------------
    For x = 0 To 1000
    rled = 0
    yled = 1
    Hserout "0", CrLf : ALSO Hserout "1", stri, crlf: ALSO Hserout stri, crlf
    Next x

    For x = 0 To 1000
    rled = 1
    yled = 0
    Hserout "1", CrLf
    Next x

    RX:--------------------------------------------------------------------------------
    Hserget i
    If i = 0 Then '< --- -- 48 is number 0
    Hserout "Number: ", i, CrLf
    rled = 1
    WaitMs 500
    Endif

    If i = 106 Then '= 106 Then '< --- -- 49 is number 1
    Hserout "Number: ", i, CrLf
    yled = 1
    WaitMs 500
    Endif
     
  2. ericgibbs

    Moderator

    Jan 29, 2010
    7,679
    1,547
    hi C,
    Why have you used Loops to Send a data string.?

    E

    EDIT:

    This is a edited clip from my HC12 receiver program.
     
    Last edited: Apr 17, 2018
  3. Ian Rogers

    Well-Known Member

    Dec 12, 2012
    608
    162
    Hi C

    I did answer on t'other place but when there is work in I have to get it done..
     
  4. Picbuster

    Well-Known Member

    Dec 2, 2013
    900
    117
    do you have https://www.elecrow.com/download/HC-12.pdf ?
    Did you give attention to the timing?
    Picbuster
     
  5. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi I,
    I will keep trying your code from t'other place, but previously on my TRACKER program, E, used a different method to glean DATA from a GPS, which is a bit more complex, but works ok. I hoped he would send me something similar for the HC-12s and he did in #2, which I need to read for a while to follow and understand.
    Now get back to work;)
    Cheers, C.
     
  6. ericgibbs

    Moderator

    Jan 29, 2010
    7,679
    1,547
    hi C,
    I try to write a program in a general way that can be later expanded as required , you are being too specific.
    eg:
    Send a message that can carry more data/instructions to the remote receiver.
    hserout "Axyz",crlf
    Using 'A' as a RXR ID sync character [ A thru Z are available]
    x, y, z characters/numbers can specify the action required a the RXR end. [ a thru z, lower case, 0 thru 9]
    Limit the TX rate to say 0.5 Sec, to give the RXR time to execute the command and ECHO back if commanded to do so.

    At the RXR, use RX/serial interrupt
    On Interrupt check for Overflow Errors, clear as required.
    Test for the Sync Character for that particular RXR, ie: 'A' etc
    If ID is valid, get the rest of the message upto the crlf code

    You can then use midstr to test the message content,
    If midtsr(rxd,p,n) then ' to pick off a character or group of characters
    if a match, then do something.!

    One of the do something characters could be an command ECHO to send an 'OK' message back to the TXR. [ or any other data msg]

    E
     
  7. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi E,
    First I'm trying to get a LED to ON/OFF in the simplest way, so if I can get I's suggestions to work, from t'other forum, I'll use that to get the feel of things. I'm sure I can think of many simple uses for it.

    Depending on how I understand your suggestion, and remembering that it will be LOOPed in a longer program with lots going on, I will probably use it in the MAIN program.
    Thanks, E.
     
  8. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi P,
    I have the Data sheet, but could you explain more please? I think it may be something to do with timing, and missing the incoming DATA, or the DATA being held in the RX and not being cleared, before the next input.
    C
     
  9. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
     
  10. ericgibbs

    Moderator

    Jan 29, 2010
    7,679
    1,547
    hi C.
    E

    This is a clip from the Tracker Interrupt.
    getmsg: 'read and save GPGGA msg
    If PIR1.RCIF = 0 Then Goto getmsg ' keep read reading until not 0
    char = RCREG ' Direct read of the RXD input buffer.
    str1(rxi) = char ' save char
    rxi = rxi + 1 ' inc bfr pointer
    If rxi > 80 Then Goto get_neo 'msg bfr over run
    If char = 0x3f Then Goto eomsg '''''''''''''''' CHANGE to 0x0A or 0x3f
    Goto getmsg


    This is a clip from poll loop
    get_neo:
    If RCSTA.OERR = 1 Then 'if over run error then flush RXD buffer
    RCSTA.CREN = 0
    RCSTA.CREN = 1
    bytchar = RCREG 'error flush bfr
    bytchar = RCREG
    PIR1.RCIF = 0
    Endif

    sync1: 'wait for a $ start of string
    cp = 0
    If PIR1.RCIF = 0 Then Goto sync1
    bytchar = RCREG ' direct read of RXD bfr
    If bytchar <> "$" Then Goto sync1 '$'
    strxd(1) = bytchar

    For ix = 2 To 79
    Hserin bytchar
    strxd(ix) = bytchar
    If bytchar = eomchar Then 'LF
    Goto echo
    Endif
    Next ix
     
  11. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi E,
    I've decided to adopt this method over the simpler method.
    Is it possible to have a GPS and an HC-12 on the same TX/RX PINs? I'm asking this for later, but for now, only the HC-12 will be connected.
    C.
     
  12. ericgibbs

    Moderator

    Jan 29, 2010
    7,679
    1,547
    hi C,
    You cannot connect two TXD driver outputs together.
    Connecting two RXD's reading inputs is OK, I often do that for monitoring.

    Post a short Oshonsoft Basic program, say driving just two LED' s Red, Yellow I can check it for you.
    E
     
  13. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi E,
    I guessed there might be a problem with double TX/RX, and bought some 18LF6722 PICS, but I better not jump ahead, just yet.
    I'll have a go at a program.
    C.
     
  14. Ian Rogers

    Well-Known Member

    Dec 12, 2012
    608
    162
    Hi C

    The pic18f45k22 has two ports...

    I have a few if you want to try them..
     
  15. Picbuster

    Well-Known Member

    Dec 2, 2013
    900
    117
    The inter character timing is always an issue when radio transmitter is not using internally an output (TX) buffer.

    For the MPU input do not use a poll mechanism but use interrupt instead.

    example
    if (RC2IF) //RX int
    {
    RC2IF=0;
    if (RCSTA2bits.OERR) // check for overrun.
    {
    RCSTA2bits.CREN=0; // clear receiver
    RCSTA2bits.CREN=1; // re-enable
    Serial.Port2Pointer=0;
    }

    if (!Serial.Port2In) // do not accept more data when block received // CR
    {
    char Receive=RCREG2; // get byte received
    if (Receive==Serial.Reset_pointer) {Serial.Port2Pointer=0;}

    if (Receive==13){Serial.Port2In = On;} // set received flag
    Serial.Port2String[Serial.Port2Pointer]=Receive;
    if (Serial.Port2Pointer>100){Serial.Port2Pointer=0;} // flush when data won't fit anymore
    Serial.Port2Pointer++;
    }
    }

    //============ in the .H file

    //------------------------------------------------------------------------------
    #define On 1
    #define Off 0

    struct{
    char Reset_pointer;
    int Port2Pointer;
    int Port2In;
    char Port2String[100];
    } Serial;
    //------------------------------------------------------------------------------

    Do not forget to set baud rate, enable interrupt and clear int flags.

    Picbuster
     
  16. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi I,
    Most kind.

    I'll have to check why I bought the 18LF6722 PICS, in case there is something special to my project. Many PINs and many uses, it's getting mighty complicated for my brain cell.

    Also I am changing to surface mount, and I wonder if your 18F45K22 are TTH type.

    Thanks very much, C.
     
  17. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi P,
    Your code looks interesting, but my system uses Oshonsoft BASIC, of the type of E's code.
    Thanks a lot,
    C.
     
    Last edited: Apr 19, 2018
  18. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi E,
    I've made a start! Is this what you expect?
    I don't think AAC allows BAS files?
    C.
     
  19. ericgibbs

    Moderator

    Jan 29, 2010
    7,679
    1,547
    hi C,
    Downloaded your files, give me a little while.:rolleyes:
    E
     
  20. camerart

    Thread Starter Senior Member

    Feb 25, 2013
    1,304
    40
    Hi E,
    No hurry, sun's out and so is my bike.
    C
     
Loading...