Using PIC to program AT commands to the HC12 radio module

Status
Not open for further replies.

camerart

Well-Known Member
Hi,
Programming HC-12 radio module is usually done by using a USB serial terminal to send COMMANDs to the modules e,g, AT+C002 to change frequency to CH2 while pulling the SET PIN down.

I would like to SEND COMMANDS using a PIC using the serial TX, e,g Hserout "AT+C002", CrLf. I've tried pulling the SET PIN down with a button to 0V also wiring a PIC PIN to pull SET down, but I can't get this to work reliably.

Any suggestions please?

Camerart.
 
Last edited:
Hi,
Quickly reading about it, I see mention of a MAX232, but I think this is toconvert the voltage. My PIC and the USB serial adaptor are both 3.3V

I also saw a mention to the DATA being negated. I'll try some tests with a logic analyser later.
C.
 
Here's a good page... It uses the HC-12 PC software tool..

But if you are going from pic -> Radio then no extra hardware is needed.. Both are TTL level and you connect it exactly th same as when you are sending / receiving... There is no negating required either..
 
Morning I,
I have an adaptor (Not quite the same) it connects to the USB on the computer, and changes settings on the HC-12 and reports back 'OK'

My problem is: changing the settings using a PIC HSEROUT, instead. I pull the SET PIN down and send changes, but they don't change. BAUD OK,
C
 
Hi,
I'm trying to get the PCB to program the HC12s using AT COMMANDs

First testing with a terminal SEND "AT+C010" HC12 returns OK C010. OK.

ON PCB.

Hseropen 9600
Hserout "Ready!", CrLf
'SET UP HC12
'PRESS BUTTON (OR EXTERNAL)
PORTE.0 = 0 'SET HC-12 COMMAND ON
Hserout "AT+C010", CrLf
PORTE.0 = 1 'SET HC-12 RUN OFF

main:
If button = 1 Then 'BUTTON NOT PRESSED
rled = 0
yled = 1
Hserout "$0", CrLf
Endif
If button = 0 Then 'BUTTON PRESSED
rled = 1
yled = 0
Hserout "$1", CrLf
Endif
Goto main
End

As can bee seen from the images, it is SENDing, see right hand side of image.
The READout at the top of the image shows the top line is some time from the start. The bottom line took me ages to decipher, and the result is shown on the second image.
Why the error?
C
 

Attachments

  • AT C010 PCB TX.jpg
    197.9 KB · Views: 370
  • AT C010 PCB RESULT.jpg
    333.1 KB · Views: 353
Is the CRLF needed in AT command?
Hi J,
I tried it without cr or lf and it was ok.
I think I changed the channels, but checking isn't as easy as you'd think. I've got SDR# and radios, but it isn't clear to check. What I did try is two modules talking to each other. One channel changed by a terminal, with an 'OK' and the other changed by PCB, they are talking.
I'll try to make it clearer.

EDIT: I'm pretty sure the TX is changing frequency, using a button to pull down the SET.
The RX uses a PIN connected to the SET to pull it down, but I can't get this to change?
C.

C.
 
Last edited:
Hi C ...When I did my HC12 code I put a third HC12 on a FTDI module and ran it with a PC terminal emulator ( Realterm ) then you can see the TX and RX bytes ...G
 
Hi C ...When I did my HC12 code I put a third HC12 on a FTDI module and ran it with a PC terminal emulator ( Realterm ) then you can see the TX and RX bytes ...G
Hi G,
I have the 3rd HC12 into a terminal.
At the moment the RX is a different PIC to the TX, so it's a faff, changing module, programming two modules, then testing them, when one isn't a TX, for that one I have to rely on a logic analyser. This isn't satisfactory, so I'm making two more PCBswith the same PIC and program, so they can talk backwards and forwards.
Thanks, C.
 
Is the CRLF needed in AT command?
Hi J,
E has just reminded me that AT COMMANDS need a CR termination.
I tried a logic analysis and here's the result, showing CR.

EDIT: CR should be LF
C
 

Attachments

  • AT C020 CR.jpg
    150.5 KB · Views: 364
Last edited:
0A is LF
0D is CR
Hi J,
I should have checked the ASCII sheet, 1ft to my right
That's what the terminal uses with AT COMMANDS, so I assume the program should also use it too?
C.
 
Last edited:
Are you monitoring the reply the HC-12 gives when you send it an AT command .... eg "C010 OK" or similar ! I also kept a byte that reflected the HC-12 baud in the nvram of a RTC chip, then on PIC start up request its setup , ie send_HC("AT+RB\r\n"); send_HC("AT+RC\r\n"); send_HC("AT+RF\r\n"); etc ... send_HC (); is my 'C' serial TX function..

Edit , I just noticed you did see replies
 
Hi G,
I'm not monitoring the return "C010 OK" at the moment, I'm relying on the channel change for verification or logic analyser.
C.
 
Hi,
With a button from SET PIN to ground the module frequency is setting, but when trying to set the SET PIN using a PIC PIN, I can't get it to SET.
Any ideas?

Using a logic analyser, it also isn't showing any movement. I'm pretty sure it's user error, but I can't think what I've got wrong!

C
 
Hi,
At last, I've found the problem!
I've added some gaps between the lines, and now this changes frequency ok.

'PRESS BUTTON (OR RADSET)
radset = 0 'SET HC-12 COMMAND ON
WaitMs 100 'MINIMUM 25
Hserout "AT+C020", CrLf '441
''''WaitMs 100
radset = 1 'SET HC-12 RUN ON
''''WaitMs 100
rled = 0

EDIT: I found the minimum WAITMS that worked is 25Ms. What would a 'safe' number be?

Thanks to all,
C.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…