• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using PIC to program AT commands to the HC12 radio module

camerart

Active Member
Thread starter #1
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:

camerart

Active Member
Thread starter #2
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.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#3
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..
 

camerart

Active Member
Thread starter #4
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
 

camerart

Active Member
Thread starter #5
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

camerart

Active Member
Thread starter #7
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:

granddad

Active Member
#8
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
 

camerart

Active Member
Thread starter #9
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.
 

granddad

Active Member
#13
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
 

camerart

Active Member
Thread starter #14
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.
 

camerart

Active Member
Thread starter #15
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
 

camerart

Active Member
Thread starter #16
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:

Latest threads

EE World Online Articles

Loading

 
Top