HC-12 response to AT-commands

friis

Senior Member
Hi,
I cant make the AT-commands work on any of my HC-12s with any of my pgms which have been working until now. When I f.ex. run hippy's pgm:

Code:
#Picaxe 14M2
#Terminal 38400
#No_Data

Symbol HC12_SET     = C.1
Symbol TX_pin       = C.2
Symbol RX_pin       = C.3

Symbol HC12BaudRate = T9600_32

PowerOnReset:
  High TX_pin
  Low HC12_SET
  SetFreq M32
  Pause 16000
  SerTxd( Cr, LF, "Started", CR, LF )

MainLoop:
  Do
    b1 ="?" : b2 = "?" : b3 = "?" : b4 = "?"
    b5 ="?" : b6 = "?" : b7 = "?" : b8 = "?"
    SerOut TX_Pin, HC12BaudRate, ( "AT" )
    SerIn [8000], RX_Pin, HC12Baudrate, b1,b2,b3,b4,b5,b6,b7,b8
    If b1 = "?" Then
      SerTxd( "No response", CR, LF )
    Else
      SerTxd( "R:", b1,b2,b3,b4,b5,b6,b7,b8, CR, LF )
    End If
    Pause 8000
  Loop
[/code/]

I get the response:

R:[80][80].....

It appears that the frequency with which HC-12 answers is different (slower) from HC12BaudRate = T9600_32 as it appears from the enclosed screen pictures of scope.
Can anyone explain?
regards
torben
 

Attachments

hippy

Technical Support
Staff member
Loose wire, wrong connections, dead modules ?

Not sure what the scope traces are meant to be illustrating but the second doesn't seem to have the same idle high polarity as the first.
 

inglewoodpete

Senior Member
Hi,
I cant make the AT-commands work on any of my HC-12s with any of my pgms which have been working until now. When I f.ex. run hippy's pgm:

Code:
#Picaxe 14M2
#Terminal 38400
#No_Data

Symbol HC12_SET     = C.1
Symbol TX_pin       = C.2
Symbol RX_pin       = C.3

Symbol HC12BaudRate = T9600_32

PowerOnReset:
  High TX_pin
  Low HC12_SET
  SetFreq M32
  Pause 16000
  SerTxd( Cr, LF, "Started", CR, LF )

MainLoop:
  Do
    b1 ="?" : b2 = "?" : b3 = "?" : b4 = "?"
    b5 ="?" : b6 = "?" : b7 = "?" : b8 = "?"
    SerOut TX_Pin, HC12BaudRate, ( "AT" )
    SerIn [8000], RX_Pin, HC12Baudrate, b1,b2,b3,b4,b5,b6,b7,b8
    If b1 = "?" Then
      SerTxd( "No response", CR, LF )
    Else
      SerTxd( "R:", b1,b2,b3,b4,b5,b6,b7,b8, CR, LF )
    End If
    Pause 8000
  Loop
I get the response:

R:[80][80].....

It appears that the frequency with which HC-12 answers is different (slower) from HC12BaudRate = T9600_32 as it appears from the enclosed screen pictures of scope.
Can anyone explain?
regards
torben[/code]
Screen shot 14 (blue trace) is "AT" but I can't determine what Screen shot 15 is saying. If it is ASCII, it is possibly at 1/4 the expected data rate. You could try modifying the serin command with T2400_32 and see if the response is intelligible.

I have to agree with hippy: after your earlier trouble with breadboards, it is very likely to be caused by a wiring/connection problem. I would transfer the circuit to a piece of Veroboard (strip board), using a socket for the PICAXE and the HC-12.
 

inglewoodpete

Senior Member
Since you have had a response from the HC-12 which is possibly at a different baud rate, it could be worth while restoring your module/s to the factory default settings.

I have just re-read the HC-12 user manual version 2.3c. Under "(1) Entering command mode", it says that the HC-12 can be forced to boot up at 9600baud, 8 data bits, no parity, 1 stop bit by holding the Set pin low before applying power to the module. Then send "AT+DEFAULT" at 9600 baud to restore the HC-12 to factory default settings.
 

friis

Senior Member
Hi inglewoodpete,
I dont trust my hc-12s so I will order new ones and continue when I get them.
torben
 

friis

Senior Member
Hi inglewoodpete,
I dont trust my hc-12s so I will order new ones and continue when I get them.
torben
Hi,
I have the transmitter-receiver system running on 2 08M2 with the following parameters:

#Terminal 38400
Baud rate T9600_32
Freq M32

I need to run the transmitter-receiver system on a 28X2 (f.ex. transmitter) and a 14M2. I tried to use the same parameters, but freq. M32 apparently is not OK for 28X2 unless I have an external resonator (I have not looked for that yet). I therefor tried run with the parameters:

#Terminal 19200
Baud rate T9600_16
Freq M16

but that did not work. The transmitter is transmitting but the receiver is not receiving anything (scope). The terminal is OK.
I would have thought that with the parameters the same for transmitter and receiver I would be OK.
Can anyone explain?
torben
 

inglewoodpete

Senior Member
You are saying that you have a 08M2 as a transmitter and another 08M2 working as a receiver. This combination works.

You should be able to swap either 08M2 with a 14M2 with minimal software changes. Can you get this to work?

The 28X2 has one or two more differences to an 08M2 but it should not be difficult to get this (28X2) to work as a transmitter or receiver.

Post your test code for an 08M2 transmitter and your equivalent code for the 28M2.

Note that it is after 11:00PM here, so I will not see your response for a few hours.
 

friis

Senior Member
Hi,
It works fine with 2 14M2.

Here is the transmitting pgm:

Code:
#Picaxe 28X2
#Terminal 19200
#No_Data

'TX test

Symbol HC12_SET     = C.1
Symbol TX_pin       = C.2
Symbol RX_pin       = C.3
Symbol HC12BaudRate = T9600_16

Symbol Countt       = b9

PowerOnReset:
    High TX_pin
    Low HC12_SET
    SetFreq M16
    Countt = 1
    SerTxd( Cr, LF, "Started PowerOnReset", CR, LF )
    pause 8000

ATinitLoop:
      Do until Countt = 6
        b1 ="?" : b2 = "?" : b3 = "?" : b4 = "?"
        b5 ="?" : b6 = "?" : b7 = "?" : b8 = "?"
            
        if Countt = 1 then
                SerOut TX_Pin, HC12BaudRate, ( "AT" )
            Countt = Countt + 1
        elseif Countt = 2 then
            SerOut TX_Pin, HC12BaudRate, ( "AT+B9600" )
            Countt = Countt + 1
        elseif Countt = 3 then
               SerOut TX_Pin, HC12BaudRate, ( "AT+C064" )
            Countt = Countt + 1
        elseif Countt = 4 then
               SerOut TX_Pin, HC12BaudRate, ( "AT+FU3" )
            Countt = Countt + 1
        elseif Countt = 5 then
               SerOut TX_Pin, HC12BaudRate, ( "AT+P1" )
            Countt = Countt + 1
        endif
        
        SerIn [64000], RX_Pin, HC12Baudrate, b1,b2,b3,b4,b5,b6,b7,b8
            
        If b1 = "?" OR b1 = "E"  Then
            SerTxd( "No response", CR, LF )
        Else
              SerTxd( "R:", b1,b2,b3,b4,b5,b6,b7,b8, CR, LF )
        End If
        
        Pause 8000
    loop
    
    high HC12_SET
    pause 8000

Main:
    b1 = 1
    b2 = 2
    b3 = 3
    b4 = 4
    b5 = 5
    b6 = 6
    b7 = 7
    b8 = 8
    
CONT:    sertxd (cr,lf,"AAAA",cr,lf)
    SerOut TX_Pin, HC12BaudRate, (b1,b2,b3,b4,b5,b6,b7,b8)
    sertxd ("Sent: ", b1," ",b2," ",b3," ",b4," ",b5," ",b6," ",b7," ",b8,cr,lf)
    pause 8000
    goto CONT
[/code/]

The receiving pgm is identical except:
1. #Picaxe 28X2 is replaced by #Picaxe 14M2
2. b1 = 0, b2 = 0,......
3. serout is replaced by serin
4. sertxd ("Sent.... is replaced by sertxd ("Received......

The problem appears to be Picaxe 28X2
torben
 

inglewoodpete

Senior Member
Hi,
It works fine with 2 14M2.

Here is the transmitting pgm:

Code:
#Picaxe 28X2
#Terminal 19200
#No_Data

'TX test

Symbol HC12_SET     = C.1
Symbol TX_pin       = C.2
Symbol RX_pin       = C.3
Symbol HC12BaudRate = T9600_16

Symbol Countt       = b9

PowerOnReset:
    High TX_pin
    Low HC12_SET
    SetFreq M16
    Countt = 1
    SerTxd( Cr, LF, "Started PowerOnReset", CR, LF )
    pause 8000

ATinitLoop:
      Do until Countt = 6
        b1 ="?" : b2 = "?" : b3 = "?" : b4 = "?"
        b5 ="?" : b6 = "?" : b7 = "?" : b8 = "?"
           
        if Countt = 1 then
                SerOut TX_Pin, HC12BaudRate, ( "AT" )
            Countt = Countt + 1
        elseif Countt = 2 then
            SerOut TX_Pin, HC12BaudRate, ( "AT+B9600" )
            Countt = Countt + 1
        elseif Countt = 3 then
               SerOut TX_Pin, HC12BaudRate, ( "AT+C064" )
            Countt = Countt + 1
        elseif Countt = 4 then
               SerOut TX_Pin, HC12BaudRate, ( "AT+FU3" )
            Countt = Countt + 1
        elseif Countt = 5 then
               SerOut TX_Pin, HC12BaudRate, ( "AT+P1" )
            Countt = Countt + 1
        endif
       
        SerIn [64000], RX_Pin, HC12Baudrate, b1,b2,b3,b4,b5,b6,b7,b8
           
        If b1 = "?" OR b1 = "E"  Then
            SerTxd( "No response", CR, LF )
        Else
              SerTxd( "R:", b1,b2,b3,b4,b5,b6,b7,b8, CR, LF )
        End If
       
        Pause 8000
    loop
   
    high HC12_SET
    pause 8000

Main:
    b1 = 1
    b2 = 2
    b3 = 3
    b4 = 4
    b5 = 5
    b6 = 6
    b7 = 7
    b8 = 8
   
CONT:    sertxd (cr,lf,"AAAA",cr,lf)
    SerOut TX_Pin, HC12BaudRate, (b1,b2,b3,b4,b5,b6,b7,b8)
    sertxd ("Sent: ", b1," ",b2," ",b3," ",b4," ",b5," ",b6," ",b7," ",b8,cr,lf)
    pause 8000
    goto CONT
The receiving pgm is identical except:
1. #Picaxe 28X2 is replaced by #Picaxe 14M2
2. b1 = 0, b2 = 0,......
3. serout is replaced by serin
4. sertxd ("Sent.... is replaced by sertxd ("Received......

The problem appears to be Picaxe 28X2
torben
The only thing I can think of at the moment is that the 28X2 may not get to the serial receive points at the right time to capture the incoming data. "Pause 8000" is not a good thing to do when you are waiting for something. Remove it altogether once you get to a point where you want to receive data from the HC-12 in the receiver PICAXE.

As a personal rule, I avoid using Pause and Wait statements anywhere in my programs: apart from the rare occasions where a time gap is required between two actions (Eg configuring the HC-12 with 40mS and 80mS pauses when changing the state of the 'Set' pin)
 

friis

Senior Member
Code:
Hi,
But the 28X2 is not receiving data - it is only transmitting.
 
What do you do in a situation like this:

    No 1                         No 2
Transmitting      Receiving
                                   Pause waiting for No 1 to be ready for receiving
Receiving             Transmitting

I tried to change the 28X2 and it made no difference.
torben
[/code/]
 

friis

Senior Member
[
Hi,
I am quite sure that when I have loaded in the pgm in the 28X2 I see a transmission on the scope and the equivalent transmission on the terminal. When I remove the AXE027 cable from the 28X2 I dont see a curve on the scope but only a blip. I still see the transmission on the terminal.
That would explain why I dont see any data received when I install the AXE027 on the receiver - not on the scope, not on the terminal.
But what explains this?
torben
 

friis

Senior Member
Hi Inglewood,
Can you imagine that I have been working with 28X2 for 4 years without tying down the serin pin and it worked! In the future I will be patient when reading datasheets and not rush it.
Thanks for your help.
torben
 

inglewoodpete

Senior Member
That is good news! The floating serin pin issue comes up from time to time on the forum but usually with new users of PICAXE.

I was fortunate that I started my PICAXE life with an AXE092 "Schools Experimenter" board, which was a small, self contained system. As you would expect, the programming socket and resistors had to be soldered in place on the board. I then joined the PICAXE forum and read of other people's PICAXE issues. Crusty older members would occasionally say "Read the manual!", or (sometimes stronger )words to that effect. I printed a copy of each manual and read them on my bus ride to work each day.
 

friis

Senior Member
Hi inglewoodpete,
Well, it was'nt all that simple after all. I cannot have the tie down resistor on while uploading the pgm -> upload, disconnect the breadboard adaptor, place the tie down resistor (10K Ohm).
And then I have to set the transmitting strength to P1 (in the 28X2) and place a helical antenna in the transmitter - and no antenna in the receiver. That works.
I assume that the P1/helical antenna has something to do with with sending at just the right level of transmitter strength - not too much, not too little.
It seems a bit fragile, but that is what I have got to work with now.
torben
 

inglewoodpete

Senior Member
Try a tie-down resistor of 100k ohms. That should pull the SerIn pin down without interfering with downloads.

All small wireless boards need at least a metre or two space to be able to work. I have a 3-metre extension lead for my downloads when needed. This allows the wireless cards and/or their aerials to be further apart.
 
Last edited:

friis

Senior Member
Hi inglewoodpete,
Thank you very much for your advice. I think manuals are woefully short of practical advice for the beginner.
torben
 
Top