Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:32 10 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CFUNCTIONs and a HC12 module

Author Message
SteveA
Regular Member

Joined: 10/03/2017
Location: United Kingdom
Posts: 48
Posted: 02:33am 13 Mar 2017
Copy link to clipboard 
Print this post

Hello all, my first post here so please be gentle!

I'm trying to use a HC12 wireless module with a MX170F256 micromite. I'm using both h/w comm ports for other purposes , so I want use the serial cfunctions.

The HC12 works on both hardware comm ports, but refuses to communicate via the cfunctions on pins 4 and 5. For example when I send 'AT', I expect to get 'OK' or at least 'ERROR' back, but I get no response at all.

Looking at the serial stream (9600bps) from the TX cfunction, I noticed that while the data bit timings are correct at ~104usec, the stop bit is always longer at ~140usec.

I have seen mentioned elsewhere that the HC11 module is a bit picky about serial timings, is the HC12 the same?

Has anyone successfully used a HC12 with the cfunctions?
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 03:13pm 13 Mar 2017
Copy link to clipboard 
Print this post

SteveA, not sure if I could help in the C-function area but as a work around given the idiosyncrasies of the HC12, have you thought of using one of the hardware ports for the HC12 and the C-function port for one of the other comms?

Graeme
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9072
Posted: 04:12pm 13 Mar 2017
Copy link to clipboard 
Print this post

Cfunction serial ports would be difficult to use with an HC-12 IF you want to be able to process what comes back from the module as responses to the commands you send it.

As OA47 says, you are far better off reserving your hardware COM ports for modules like this.

Not saying it is impossible to do what you are trying to do, but the problem is that by the time you send the command to the HC-12, then switch to the Cfunction that listens for the response, you might have missed it.

The beauty of the hardware COM ports, is that they are buffered in the background, and are perfect for catching replies from modules like this, cos that data will be saved from the module in the COM port buffer, regardless of what the main program is doing, then you just need to read the buffer and analyse the replies.

From what I remember, the serial receive Cfunction is blocking, in that you can specify a timeout, but during that time, nothing else can be processed till the timeout occurs and the Cfunction returns with whatever was received. This means the rest of your program has to wait for the Cfunction to return. This may or may not be a problem depending on what you are doing.

What do you have currently on the hardware COM ports?

Oh, and welcome aboard.
Smoke makes things work. When the smoke gets out, it stops!
 
SteveA
Regular Member

Joined: 10/03/2017
Location: United Kingdom
Posts: 48
Posted: 01:52am 14 Mar 2017
Copy link to clipboard 
Print this post

Thank you for the suggestions, and the welcome!

On reflection, I was probably asking too much of the cfunctions!

I currently have a ESP8266 and RS485 transceiver on the h/w ports. The idea of the HC12 is to extend comms to places I can't run a RS485 cable to.

I think it might be possible to put the HC12 and RS485 on the same h/w port. This will be the only master unit, so it will control all communications. Slaves won't be able to talk to it until they are asked, so I should be able to avoid conflicts. Time for an experiment!

If that doesn't work, I have a bare 64 pin micromite+ pcb I bought ages ago and never got around to building, so that will give me an extra comm port.

 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3022
Posted: 05:21am 14 Mar 2017
Copy link to clipboard 
Print this post

SteveA--can you share your hardware setup and sample code for your RS485 layout?

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
SteveA
Regular Member

Joined: 10/03/2017
Location: United Kingdom
Posts: 48
Posted: 04:59am 16 Mar 2017
Copy link to clipboard 
Print this post

For the hardware I use breadboard compatible 3v3 modules, search eBay for '3.3V UART Serial To RS485 SP3485 Transceiver Converter Communication Module' look for ones on a small red pcb.

So I can see what's happening on the bus, I use a USB to RS485 converter plugged into my PC, search eBay for 'USB to RS485 USB-485 Converter Adapter Support Win7 XP Vista Linux Mac OS' You can use any terminal software, I use Putty on Win7.

I have found you need to add a couple of 1K resistors from A to GND, and B to VCC on one module to get things working.

The red pcbs have a 220r resistor between A and B, you only need these on the ends of the line, so if you have lots of nodes and get communication errors try removing them.

I'm only hacking about at the moment, so I don't have any finished software to post. But it's easy to get working using the examples in the micromite manual - if you use COM1 the micromite even handles the RTS (they call it EN) pin which switches the IC between listening and sending.

Use OPEN to setup your port (I'm using 9600 8N1), PRINT #n to send and INPUT() or LINE INPUT to receive.

Steve
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3022
Posted: 06:46am 16 Mar 2017
Copy link to clipboard 
Print this post

Thanks. Modules ordered by slow boat. I had wondered what that COM1 Enable meant.

Lance

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024