40X2 with HC-12 to 14m2 with HC-12

mushroom

New Member
Hi,
I've had great success transmitting between similar Picaxe chips with HC-12 transceivers.
This time I'm failing to transmit from a 40X2 to a 14M2. Programs for both include "setfreq m8".
Both HC-12 transceivers work between 2 of 40X2 or 2 of 14M2. Just not one of each control chips.
Any ideas as to my errors? What am I missing?

Please relieve my stress and make me happy.
Fungal Pete
 
When you say "Both HC-12 transceivers work", do you mean that you only have two HC-12s and those same actual modules work when paired with a 2 x 40X2 or 2 x14X2? Or do you have many HC-12s?

I have found that all HC-12s don't talk reliably to all (other) HC-12s. I've had to pair them together - I'm guessing that they're not all running at exactly the same frequency.

Alternatively, you don't say if you're using bit-banged serial (ie SerOut) with either chip or if the 40X2 is using hSerial and the scratchpad. I'm pretty sure that the 14M2 inserts a short pause between each transmitted character. The 14M2 probably won't be able to keep up with the 40X2's hSerOut output strings.
 
This time I'm failing to transmit from a 40X2 to a 14M2. Programs for both include "setfreq m8".
Both HC-12 transceivers work between 2 of 40X2 or 2 of 14M2. Just not one of each control chips.

You can test that the HC-12's can talk to one another, using a pair of USB<-->Serial adaptors and two Terminal Emulators (Putty etc)

EDIT: Something like this can be useful too.

I think you may have a timing problem- the sender needs to be sure the receiver has already issued its serin before it starts sending data. This synchronisation can be achieved through the use of 'pauses' at the TX end and 'qualifiers' at the RX end. Alternatively, you could use an interrupt arrangement - and provide some throwaway characters as the first part of the message).

My belief is that the HC-12 buffers data, so differences in processing speed shouldn't be an issue. (I think I'm right in saying that different baud rates can be used at each end of the link, in which case there must be buffering).

(I had a project, where a 20X2 successfully exchanged data (both ways) with 6x14M2 based nodes. The 20X2 was at 64MHz, the 14M2's @ 32MHZ and comms to/from the HC-12's at 9600baud. It used the aforementioned interrupt mechanism at the 20X2 end).


14M2 code snippet (Master)
Rich (BB code):
      Enable_HC12                                           ;Bring the HC-12 radio module out of low power mode
      Serout tx_pin,HC12BaudRate,(Lf,"*U*U*")               ;Any character will wake up the CCU. Note - there is no guarantee as to the 
                                                            ;inter-byte spacing of data transmitted via the HC-12 radio module
      NAP 2; 72mS                                           ;Give CCU time to post a SERIN
      ;
      ; Send data,via 458MHz HC-12 module, as comma delimited ASCII values.
      ;
      ; Outbound Protocol:
      ; <preamble> <pause> START SensorNo,Temperature,STATE,BatteryVoltage,ConnectAttempts,NodeType,SequenceNo,CRC<cr>
      ;
      Serout TX_Pin,HC12BaudRate,("START ",#Sensor,",",#Temperature,",",#OnOffFlag,",",#SupplyVoltage,",",#ConnectAttempts,",",#MsgSeqNo,",",#CRC,Cr)
      ;
      ; Wait maximum of 250mS for a response. That is plenty of time for our message to go (20mS), write to be initiated and 
      ; characters received back.  (250 * 8 = 2000)
      ;
      Serin [2000,HC12_Timeout], RX_Pin, HC12BaudRate, ("REPLY "),#Sensor1,#Sensor2,#Sensor3,#Sensor4,#Sensor5,#Sensor6,#RcvdMsgSeqNo,#rcvdCRC ; Get responses
      ;
      ;We come here if all responses seen - else we skipped to "HC12_Timeout"
      ;
      ;DATA SENT, RESPONSE RECEIVED - SWITCH OFF HC-12
      ;
      Disable_HC12                                          ;put HC-12 radio module into low power mode

20X2 code snippet (Slave)
Code:
;    **********************************************************************
;    Interrupt handler for HC-12 458MHz Radio module receiving a character.
;    **********************************************************************

    ;;; This used to be an interrupt routine for an HC-05 Bluetooth module asserting "STATE"...
  
    ;;;
    ;;; HC-12 STATE (actually TXD) went LOW, signifying serial data arrival
    ;;;
    ;;;      Use SERIN command with a timeout and  a prefix to receive the data.Using the "#"
    ;;;      variable format means it terminates the instant it sees the " " in front of " END".
    ;;;

    ;;;
    ;;; Post a read to get the data as it arrives. (Sender waits after connection made, to give us time to post the read)
     ;;; 4000 = 500mS Sec. timeout @ 64Mhz. [Data will normally be here in about 63mS]
    ;;;
    ;;; The data sent is: <lf>'*U*U' <pause 40ms> 'START sensornumber,Temperature,RemoteNodeState,BatteryVoltage,NegotiationAttempts,MessageSequenceNumber,CRC)<CR>
    ;;;
    ;;; It takes a minimum of 500uS to get here, so the first byte is already gone. In other words, we only see some of the "*U*U*" + "START sensornumber etc".
  

    Serin [4000,HC12_Timeout], DATA_IN, HC12baudrate, ("START "),#ISensorNumber,#Temperature,#RemoteNodeState,#Battery,#NegAttempts,#MsgSeqNo,#RcvdCRC

    ;;;DebugSensorNumber = ISensorNumber            ;;;Save Sensor number, as received - for debug  (not needed when Repeater concept removed in V5.1.0)
    ;;;
    ;;; Calculate expected CRC for received message
    ;;;

;;;TUNE THIS - may not need to wait very long at now we're calculating CRC's
;; Experimental - seems fine:    Pause 80            ;;;wait 10mS for remote node to post 'Serin' statement

    Serout DATA_OUT,HC12baudrate,(lf,"REPLY ")    ;;;send first part of response
  
    For b0 = 1 To MaxSensors                ;;;6 sensors.
        Read SetPoints,Word W3
        Serout DATA_OUT,HC12baudrate,(#W3,",")    ;;;send next value
        SetPoints = SetPoints + 6            ;;;point at next entry
    Next b0

    Serout DATA_OUT,HC12baudrate,(#MsgSeqNo,",",#CRC,cr) ;;; V5.0.0 Protocol - repeat sequence # and add valid  CRC alongwith a <CR>



    hint2flag = 0                        ;;;reset interrupt
 
In stress mode yesterday. Job delayed now until February. (more time). Job is 2 days and nights, 500 km away. Was to travel to Job today. Transceivers for our staff use, not customers. Without transceivers we would need 4 more workers than we have.

Thanks Pete and Phil. I have many HC-12 units. Have used HC-12's many times, using 14M2's, 20X2's, 20M2's and 40X2's. Never before 40X2 to 14m2.
I will use today to double check all hardware, a master and 4 slaves. Then re-look at my software.
This done, I will report back hopefully with positive results, or more questions. Note that I'm only sending a 4 byte qualifier and 3 bytes of data every 5 minutes.
Pete
 
Make sure you have the correct suffix on the baud rate when using different chip sizes that have a different default operating frequency ( and hence different default baud rates). e.g. N2400_8 not N2400
 
Sorry for the delayed reply.
Problem is solved. I have 3 different PCB's for 40X2's and forgot that I'd changed the serial pins used for the on-board HC-12's. Silly mistake. Twit.

Wanted to use the state of individual bits in a byte in B0 and B1 memory. Picaxe manual 2 suggests that this is OK with X2 chips and not M2's. I found that this worked fine on 14M2's but apparently not on 20M2's. I hope this helps someone and that no one suggests a problem with it.

Technical, I did have that correct and also set frequency to setfreq m8 early in the programs. I assume you mean that both chips can run on different default frequencies as long as the correct suffix is on the baud rate. Useful info for me.

Thanks all who replied above. I learned some from all comments.
I'll have more time to tinker after July next year when I retire at age 67. I'll still have 3 teenagers then, but only one under 18yrs. (17, 18 and 19yrs)
 
You can certainly use the state of individual bits in b0, b1, b2, and b3 on all M2 chips. Can you post code which you feel shows it not working on the 20M2?

Also, where in Manual 2 does it suggest to you that using bit0-bit31 will not work on the M2 devices? (As I recall, the X2s do have commands which the M2s lack to work with bits in the variables above b3, but the bits are not individually addressable as are bit0-bit31.)
 
Ibenson, Thanks heaps.
Can't find where I misread or misunderstood manual info but you are right. Your comment encouraged me to recheck my code when using 20M2's.
I found an error and fixed it. NOW it DOES WORK.

Merry Xmas all. We expect 35deg C and no snow here Xmas Day. Not too hot. Not too cold. Ho, Ho, Ho.
 
Back
Top