PIC 18LF4431 RX not receiving.

Thread Starter

camerart

Joined Feb 25, 2013
1,917
Hi,
I have had two PICs talking to each other TX RX, via HC-12 radio modules. 18LF4520 to 18LF2431. I've now changed the RX PIC to 18LF4431. Programmed using Oshonsoft.

Here is the TX LOOP (MAIN):
main:
If button = 1 Then 'BUTTON NOT PRESSED
rled = 0
yled = 1
Hserout "$0", CrLf
waitms 100
Endif
If button = 0 Then 'BUTTON PRESSED
rled = 1
yled = 0
Hserout "$1", CrLf
waitms 100
Endif
Goto main

This is being received by a third HC-12 USB serial input to a Terminal ok.

Here is the RX program: The program is also a memory test for the PIC, so there are sections for use later, but it still compiles in Oshonsoft

I have attached a Logic analyser to the RX PCB, RX PIN and it shows the $0 or $1 is arriving at the PIN ok but not switching the LEDs as expected. It works in the Oshonsoft SIM.
Any ideas?
Camerart.
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi C,
You need a short delay after Hserout, so that the RX can complete the command that was sent.
Say 100mSec
E
Hi E,
Ah yes, you suggested this earlier, and I use it, but forgot to show it in POST#1 which is now updated. This didn't get the RX to work.
Thanks, C.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
9,786
hi C,
When you send this block. [ high lighted line], where do you read the reply.? and what do read from the response.??
E

'main:
'PRESS BUTTON (OR RADSET)
radset = 0 'SET HC-12 COMMAND ON
WaitMs t
Hserout "AT+P8", CrLf '1= -1DB Lowest power- 8=20DB
WaitMs t
Hserout "AT+C001", CrLf '433.4
'Hserout "AT+C020", CrLf '441
WaitMs t
Hserout "AT+RX", CrLf
WaitMs t
radset = 1 'SET HC-12 RUN ON
wled = 0
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi C,
When you send this block. [ high lighted line], where do you read the reply.? and what do read from the response.??
E

'main:
'PRESS BUTTON (OR RADSET)
radset = 0 'SET HC-12 COMMAND ON
WaitMs t
Hserout "AT+P8", CrLf '1= -1DB Lowest power- 8=20DB
WaitMs t
Hserout "AT+C001", CrLf '433.4
'Hserout "AT+C020", CrLf '441
WaitMs t
Hserout "AT+RX", CrLf
WaitMs t
radset = 1 'SET HC-12 RUN ON
wled = 0
Hi E,
So far I can only READ them at the RXPCB: HC-12 TX PIN-PIC RX PIN, via a Logic analyser. (I'll need to be pedantic when writing the TX RXs, it's easy to get mixed up)
Here is the TXT READOUT:
Also, Channel 00 of the Analyser shows text, which I can read, this is why I'm using it for the RXPCB RXPIN.
CH1 shows RXPCB TXPIN.
CH2 shows the SET PIN (RADSET) of the HC-12. (This may be going HIGH to fast?)

Can you confirm that no HSERIN is used please?

C.
 

Attachments

ericgibbs

Joined Jan 29, 2010
9,786
hi,
When you send Hserout "AT+RX", CrLf
The remote responds with
ESP1 12-May-18 10.26.gif

If your program does not read and verify this response, there is no point in sending it.
You should verify in the response, that your remote setting instruction has been accepted.
[the set up instructions may not have been received correctly by the remote]

E
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi,
When you send Hserout "AT+RX", CrLf
The remote responds with
View attachment 152368

If your program does not read and verify this response, there is no point in sending it.
You should verify in the response, that your remote setting instruction has been accepted.
[the set up instructions may not have been received correctly by the remote]

E
Hi E,
I'll use your suggestion of BASE and REMOTE for TXPCB and RXPCB.

To clarify!
Today we have only been talking about the REMOTE, apart from when I test using the BASE to send $0 or $1.

When the REMOTE PIC starts up it sends the 'AT' settings to the HC-12. The HC-12 reports back to the REMOTE, 'OK' each time, as reported by the analyser.
This is working as the channel changes, if the program is changed.

C.
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
Hi E,
Just had a thought regarding BAUD RATE.
The BASE has the [ OSCTUNE.PLLEN = 1 '*4 PLL enabled so Fosc = 32MHZ ] line, but the REMOTE doesn't.
I'm just checking the D/S

P.S It was suggested before, but I forgot where and when!

C
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
Hi,
I got the BASE to work sporadically, by adding a Serial terminal (1) instead of the HC-12 to the RX PIN. I had a second terminal (2) to monitor any output.

I narrowed the problem around the 'If char <> 0x24 Then Goto sync1 '$' line and tried WAITs and HSEROUTs, till it worked sporadically.

Anyway, I went round the houses for a couple of days, and now it's working in it's original form, and I didn't find out what the problem was?

C.
 

ericgibbs

Joined Jan 29, 2010
9,786
hi C,
Good news, thanks for the feedback.
As you know I have a similar set up working 24/7.
Lets hope the problem doesn't return.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi C,
Good news, thanks for the feedback.
As you know I have a similar set up working 24/7.
Lets hope the problem doesn't return.
E
Hi E,
Let's hope!
I'm now trying an 'echo' where the BASE sends a signal, the REMOTE replies, switching LEDs on the BASE. Then I'll try Antenna range tests.
C.
 

ericgibbs

Joined Jan 29, 2010
9,786
hi C,
Remember if you want to Echo back from the Remote, store the received data in a buffer in the Remote, test for <crlf>, then add a delay before echoing.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi C,
Remember if you want to Echo back from the Remote, store the received data in a buffer in the Remote, test for <crlf>, then add a delay before echoing.
E
Hi E,
I kind of understand what you mean. I've been puzzling how BASE and REMOTE can be listening and talking at the same time, and I assume this is how to get over it.
When you say store the DATA, do you mean IN = X, then work with X ?

Can the delay be a section of program? What I mean is I envisage the program getting quite long eventually, can this be used as a delay? Also for HSEROUT---some program, instead of WATMS100
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
Hi E,
I can see that this is rather complicated for me, so I think I will try writing simpler HSERIN HSEROUT programs dedicated to antenna testing with no If char <> 0x24 Then Goto sync1 '$' line.
C.
 

ericgibbs

Joined Jan 29, 2010
9,786
hi C,
A possible problem will be that any RX errors in the Remote will not be cleared unless you add the following code.
Post a clip of the TX & RX code, just a clip.
E

If RCSTA.OERR = 1 Then 'RCSTA BIT1-if over run error then flush RXD buffer
RCSTA.CREN = 0
RCSTA.CREN = 1
char = RCREG
PIR1.RCIF = 0
Endif
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi C,
A possible problem will be that any RX errors in the Remote will not be cleared unless you add the following code.
Post a clip of the TX & RX code, just a clip.
E

If RCSTA.OERR = 1 Then 'RCSTA BIT1-if over run error then flush RXD buffer
RCSTA.CREN = 0
RCSTA.CREN = 1
char = RCREG
PIR1.RCIF = 0
Endif

Hi E, REMOTE
Hserout "MAIN", CrLf

main:
rxi = 0
If RCSTA.OERR = 1 Then 'RCSTA BIT1-if over run error then flush RXD buffer
RCSTA.CREN = 0
RCSTA.CREN = 1
char = RCREG
PIR1.RCIF = 0
Endif

sync1: 'wait for a '$' start of string
If PIR1.RCIF = 0 Then Goto sync1
char = RCREG
'If char <> 0x24 Then Goto sync1 '$'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
str1(1) = char 'STR1 ARRAY
rxi = 2

get_msg: 'read and save
If PIR1.RCIF = 0 Then Goto get_msg
char = RCREG
str1(rxi) = char 'STR1 ARRAY
rxi = rxi + 1

If char = 0x0a Or char = 0x3f Then Goto decode 'tests for either LF or ?
Goto get_msg

decode:
If str1(2) = "0" Then
Hserout "$0", " FROM 4431", CrLf
WaitMs 200
wled = 0
yled = 1
Endif

If str1(2) = "1" Then
Hserout "$1", " FROM 4431", CrLf
WaitMs 200
wled = 1
yled = 0
Endif
Goto main
End
##################################################################################
BASE

main:

If button = 0 Then 'BUTTON PRESSED
Hserout "$1", CrLf
'WaitMs 100
Endif
If button = 1 Then 'BUTTON NOT PRESSED
Hserout "$0", CrLf
WaitMs 100
Endif

rxi = 0
If RCSTA.OERR = 1 Then 'RCSTA BIT1-if over run error then flush RXD buffer
RCSTA.CREN = 0
RCSTA.CREN = 1
char = RCREG
PIR1.RCIF = 0
Endif
sync1: 'wait for a '$' start of string
If PIR1.RCIF = 0 Then Goto sync1
char = RCREG
'If char <> 0x24 Then Goto sync1 '$'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
str1(1) = char 'STR1 ARRAY
rxi = 2

get_msg: 'read and save
If PIR1.RCIF = 0 Then Goto get_msg
char = RCREG
str1(rxi) = char 'STR1 ARRAY
rxi = rxi + 1

If char = 0x0a Or char = 0x3f Then Goto decode 'tests for either LF or ?
Goto get_msg

decode:
If str1(2) = "0" Then
Hserout "$0", " FROM 4520", CrLf
WaitMs 200
rled = 0
yled = 1
Endif

If str1(2) = "1" Then
Hserout "$1", " FROM 4520", CrLf
rled = 1
yled = 0
WaitMs 200
Endif

Goto main
End

EDIT: The REMOTE appears to be workng.
If the BASE is RESET, with no button pressed, then no BASE LED.
IF the BASE is RESET wth BUTTON pressed, then BASE WLED comes on. (Intermittent)


C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
1,917
Hi,
Ive updated both programs in #16.
The REMOTE sits with YLED on till signal from BASE where the YLED goes on instead. This seems to work ok, and transmits back either $0 or $1 to BASE.

The BASE must be RESET for any change. BUTTON not pressed = no LED at BASE, BUTTON pressed = RLED at BASE
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi C,
Good news, thanks for the feedback.
As you know I have a similar set up working 24/7.
Lets hope the problem doesn't return.
E
Hi E,
I recall that you have a set up working, for a weather station or greenhouse monitor, I think.

Are you using the little coil antenna, or another type? What distance are you getting?

Cheers, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
1,917
hi,
Coil antenna at both ends.
40 mtrs thru 3 brick walls.

E
Hi E,
I just tried line of sight and got approx 80mtrs.
I'll now add some better antennas, and see how far I can get.
It's quite a luxury, having instant feedback from the REMOTE, previously I had to leave a camera then review it later.
Thanks, C
 
Top