PDA

View Full Version : Wireless modules - help with code not working



tasmod
- 26th April 2013, 10:18
Following on from the thread where I asked re simple setup I bought the modules from Ciseco.

I've made up a board based on the schematic below and also some code, however it doesn't work. I have made a small test code just to get the module to transmit but no joy.

I can see on the scope that the pic sends the serout at 1 second intervals but I can't seem to get the module to transmit.

Factory default according to the site is 9600baud in transparent serial mode. The modules are the ARF version from Ciseco as per previous thread.

I've tried serout and serout2.

Can anyone see what the problem may be ?


'
INCLUDE "ALLDIGITAL.pbp"
Include "modedefs.bas"
DEFINE OSC 10


TRISA=$00001000
CMCON=7


TESTBIT VAR BYTE


TESTBIT = 1


TEST:
SEROUT PortA.2,N9600,["BOB",TESTBIT] '9600bps
PAUSE 1000
GOTO TEST


END


6981

tasmod
- 26th April 2013, 11:47
In the example I have the module input pin incorrect.

I've tried the other pin and still no success.

Demon
- 26th April 2013, 14:36
Does it need a short delay before the first transmission?

No need for pull-up or down resistors on lines?

(Just throwing ideas,)

Robert

tasmod
- 26th April 2013, 15:36
Hi Robert,

Thanks for the ideas.

I incorporated a start delay in one version of the code but it made no difference.

It's all at 3.3v. According to code samples on Ciseco forum it should work with direct connection but i did wonder about this myself.
Maybe I'll try them. Documentation is sparse and confusing.

I wrote a routine that cycled through all the baud rates available, one by one, per second, but the module just didn't transmit. I watched the module input pin signals on a scope and could see the pic output arriving every second, so the code worked.

I've just received an account email for Ciseco forum activation and have posted on their forum regarding the problem. They only offer support via the forum.

Rob

Dick Ivers
- 26th April 2013, 20:50
Did you try HSEROUT?

tasmod
- 27th April 2013, 17:35
Thanks Dick,

Tried that but no luck.

Seems from info from the user forum that they are faulty.

I can see signal applied to module from pic but there's no output, the main module is clocking but the rf output part isn't responding.

Rob

Dick Ivers
- 27th April 2013, 23:28
Rob,
I will be following your story with great interest. I have a similar project underway. I've purchased two XRF transceivers for breadboard testing. Not fired up yet ... still waiting for 3.3 V regulators from Digikey. My ultimate plan is a long range, one-way link with an ARF on the sending end a SRF receiver ... very much like your project.

Yes, saw your thread on the Ciseco forum. It does sound like your parts are defective .. Will be interested in how it resolves. BTW, I was not able to join the forum ... verification not working.
Regards,
Dick

tasmod
- 28th April 2013, 10:35
Dick,

Yes it was interesting to say the least on their forum.

They didn't seem to like it when I gave them test results. What exactly did they want as a post "It doesn't work" perhaps, with no details of tests carried out.

Can't believe he thought that scope results weren't useful.

Trouble is for me, my friend paid for all the parts for this project. So far he's up to $200 ish for everything for the two units. That's not far off a commercially available solution. If I return the modules for a refund, which I don't want to do I prefer a tested pair, then there's still the ancillary parts to account for.

If you need a simple design for a yagi aerial for greater range I have a doc with details of one.

Rob

Ioannis
- 28th April 2013, 13:29
I am intersted in the yagi design. If you can post it I 'd be oblidged.

Regarding the modules of yours, I am not familiar with these, but have tested xbee pro 868 and are more than great.

Also have tested y-lynx.com modules and they are even better but larger in size and price.

Ioannis

tasmod
- 29th April 2013, 09:56
Hi Loannis,

I have two docs in Word format which are pages from the internet. (Can't remember where from)

I will try to add them as attachments here. If they don't attach I will post a link to a hosting for a few days downloading.

Rob

Ioannis
- 29th April 2013, 14:02
Hi Rob. Thanks for the files. I found also the corresponding sites too.

Ioannis

Dick Ivers
- 5th May 2013, 16:58
Rob,
I now have my two XRF transceivers set up and functioning. However, I'm experiencing the same problem as you have reported ... unable to communicate rf from a PIC and PBP.

The hardware and wiring checks out good. Using a terminal program (TeraTerm) and a USART to USB Bridge cable (CP210x), the radio loop-back link works perfectly. Also, the AT command mode functions correctly for both devices.

The comms do not work when driving the radio from a PIC USART. Sample code:

'************************************************* *************************
'*Program to test XRF radio communications via loopback method *
'*Uses a pushbutton switch on porta pin 4 *
'*Target processor is PIC 12f1822 *
'*321 program words, revised 05/05/2013 *
'*Program by Dick Ivers *
'*All rights reserved *
'************************************************* *************************
'set 12f1822 configurat1on
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CLKOUTEN_OFF & _WDTE_ON
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#endconfig

'set registers
OSCCON = %01101000 '4 mhz osc
OSCTUNE = 0 'factory calibration
ANSELA = 0 'all digital inputs
OPTION_REG.7 = 0 'global pullups enabled
WPUA = %010000 'porta pin 4 weak pullup enabled
CM1CON0.7 = 0 'comparator disabled
TRISA = %011110 'PORTA.0 & porta.5 are outputS, all others input

while OSCSTAT.0 = 0 'wait for stable freq.
wend

define OSC 4 '4 mhz oscillator

'Define hserout parameters
define HSER_RCSTA 90h
define HSER_TXSTA 20h
define HSER_BAUD 9600
define HSER_CLROERR 1 'clear overflow error

APFCON.7 = 1 'rx on ra1 (12f1822)
APFCON.2 = 1 'tx on pin ra0 (12f822)

i var byte
char var byte


For i = 1 to 3
porta.5 = 0 'led on
pause 333
porta.5 = 1 'led off
pause 333
next


asleep:
nap 2 'delay 4 ms
if porta.4 = 1 then asleep


DT:
hserout [dec 5]
hserin 100,blink,[dec char]
if char = 5 then
porta.5 = 0 'led on
goto halt
endif

blink:
porta.5 = 0 'led
pause 50
porta.5 = 1 'led off
pause 50
if porta.4 =1 then asleep
goto DT

halt:
stop


I saw your latest post on the Ciseco forum. You are not getting much help there. Do you have any further test results?

Dick

Ioannis
- 6th May 2013, 11:20
@ tasmod:

You are using Serout with N9600 but I think the modules you are using need data be in true mode and not inversed. So use serout with T9600.

@ Dick:

I think for the 1822, you need to set TXSTA at $24. At $20 no 9600 is supported.

Look at page 299-300 of the data sheet.

Ioannis

Dick Ivers
- 6th May 2013, 16:31
Ioannis,
Thanks, I will try your suggestion. Unfortunately, not right now ... my computer broke down over the weekend. I'm writing this from a borrowed laptop.
Dick

tasmod
- 7th May 2013, 09:12
Hi Dick, Loannis,

I received the modules back on Friday just as I was leaving to have a few days away for the Holiday long weekend in UK.

They have been tested as OK but that doesn't relate as I couldn't measure any RF out when I sent them back. Never the less I believe Ciseco, so I'm continuing by etching two new pcbs with link pad outputs so I can link any pin to the module.

They should be complete today and populated. Then I will do more tests.

The speed issue came up so I'm running at 10MHz so 9600 should work reliably. As for True, well the Picaxe code sample seems to use N9600 but I seem to remember I didn't trust this. So I wrote a loop of serout/serin with all baud rates one after another for testing. I think I mentioned this earlier in the post. Ciseco claim any serial comms sent, will be echoed out. Their data sheet isn't any clearer.

I can use any pin/s so I will test HW serial and serout/in. Hopefully with some sort of result, as these are not my modules.

I do have access to a full professional RF spectrum test setup, however without serout/in comms working there is no point using it.

Rob

tasmod
- 7th May 2013, 19:21
At last. Working.

Redesigned pcb's but not reconfigured. Just turned pic sideways for ease of removal and added pads for each pin to facilitate cross connection, although not finally needed.

After making up the boards I wrote the most simple TX/RX routines and connected the 3 pins needed with temporary jumpers. They immediately talked to each other. Replacing the jumpers with the modules and they talked !!!!

There was one change in code that needed to be added but later removal and they still talked although not quite 100%. That was the extra first characters "SSSSSSSSBOB" before the required string to match the serin string of "BOB"


Send code -------------



Include "modedefs.bas"
DEFINE OSC 10


TRISA = %00000000

CMCON=7

pause 2000

TEST:
serout PortA.3, T9600,["SSSSSSSBOB"]
PAUSE 500
GOTO TEST
END



Receive code -----------------------------



Include "modedefs.bas"
DEFINE OSC 10

TRISA = %11111101

CMCON=7

relay var PortA.1


low relay

pause 2000

TEST:
low relay
pause 100
serin PortA.2,T9600,["BOB"]
high relay
PAUSE 1000
GOTO TEST

END

Now I need to expand the code to do just what I want and to then add a decent antenna to get the range.

I'm considering a 'Moxon' Rectangle which gives 3dbd gain with excellent f/b ratio fitted directly to modules via short solid wire. It can be made up using UK twin earth cable wire. About 1.5mm copper. It's very small indeed at 123x46mm

Rob

Demon
- 7th May 2013, 23:23
You pause 500 after transmit, but pause 1000 after reception?

Robert

Ioannis
- 7th May 2013, 23:51
Besides what Robert noted, you have to setup port A.3 as high before transmitting. RS232 needs a standard state before tx/rx.

So, I suppose T9600 made the difference?



Include "modedefs.bas"
DEFINE OSC 10

high porta.3
TRISA = %00000000

CMCON=7

pause 2000

TEST:
serout PortA.3, T9600,["SSSSSSSBOB"]
PAUSE 500
GOTO TEST
END


Ioannis

Dick Ivers
- 8th May 2013, 01:38
Hi all, I'm trying the true mode, but my loopback setup is still not working.


'************************************************* *************************
'*Program to test XRF radio communications via loopback method *
'*Uses a pushbutton switch on porta pin 4 *
'*Target processor is PIC 12f1822 *
'*207 program words, revised 05/07/2013 *
'*Program by Dick Ivers *
'*All rights reserved *
'************************************************* *************************
'set 12f1822 configurat1on
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CLKOUTEN_OFF & _WDTE_ON
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#endconfig

'set registers
OSCCON = %01111000 '16 mhz osc
OSCTUNE = 0 'factory calibration
ANSELA = 0 'all digital inputs
OPTION_REG.7 = 0 'global pullups enabled
WPUA = %010000 'porta pin 4 weak pullup enabled
CM1CON0.7 = 0 'comparator disabled
TRISA = %011110 'porta.0 & porta.5 are outputs, all others input

while OSCSTAT.0 = 0 'wait for stable freq.
wend

define OSC 16 '16 mhz oscillator

'Define debug parameters
DEFINE DEBUG_REGG PORTA 'set debug port to porta
DEFINE DEBUG_BIT 0 'use pin ra0 of porta for debug
DEFINE DEBUG_BAUD 9600 'set baud rate to 9600
DEFINE DEBUG_MODE 0 'communicate in true mode

DEFINE DEBUGIN_REGG PORTA 'set debug port to porta
DEFINE DEBUGIN_BIT 1 'use pin ra1 of porta for debugin
DEFINE DEBUGIN_BAUD 9600 'set baud rate to 9600
DEFINE DEBUGIN_MODE 0 'communicate in true mode

i var byte
char var byte

For i = 1 to 3
porta.5 = 0 'led on
pause 333
porta.5 = 1 'led off
pause 333
next

asleep:
nap 2 'delay 4 ms
if porta.4 = 1 then asleep

DT:
debug 55
debugin 100,blink,[char]
if char = 55 then
porta.5 = 0 'led on solid
goto halt
endif

blink:
porta.5 = 0 'led
pause 500
porta.5 = 1 'led off
pause 500
if porta.4 =1 then asleep
goto DT

halt:
stop 'led stays on


The communications not working. The led blinks when the remote transceiver is not powered, as it should. When its powered the program should branch to a solid on led , but no it keeps blinking. Any ideas?

Ioannis
- 8th May 2013, 08:10
Dick, I would suggest at first to test your code with a PC and see if you have the PIC working. For this you will need a MAX232 or similar to invert and drive the serial port.

If this test passes please post your results. But I have a feeling that it won't.

Ioannis

P.S. Also try with capitals in define OSC 16. As this: DEFINE OSC 16. Just in case...

Dick Ivers
- 8th May 2013, 18:07
Ioannis,
PIC to PC is working. Code and setup as follows:


'************************************************* *************************
'*Program to test PIC to PC communications via loopback method *
'*Target processor is PIC 12f1822 *
'*142 program words, revised 05/08/2013 *
'*Program by Dick Ivers *
'*All rights reserved *
'************************************************* *************************
'set 12f1822 configurat1on
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CLKOUTEN_OFF & _WDTE_ON
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#endconfig

'set registers
OSCCON = %01111000 '16 mhz osc
OSCTUNE = 0 'factory calibration
ANSELA = 0 'all digital inputs
OPTION_REG.7 = 0 'global pullups enabled
WPUA = %010010 'porta pin 1 and pin 4 weak pullups enabled
CM1CON0.7 = 0 'comparator disabled
TRISA = %011110 'porta.0 & porta.5 are outputs, all others input

while OSCSTAT.0 = 0 'wait for stable freq.
wend

define OSC 16 '16 mhz oscillator

'Define debug parameters
DEFINE DEBUG_REGG PORTA 'set debug port to porta
DEFINE DEBUG_BIT 0 'use pin ra0 of porta for debug
DEFINE DEBUG_BAUD 9600 'set baud rate to 9600
DEFINE DEBUG_MODE 1 'communicate in inverted mode

DEFINE DEBUGIN_REGG PORTA 'set debug port to porta
DEFINE DEBUGIN_BIT 1 'use pin ra1 of porta for debugin
DEFINE DEBUGIN_BAUD 9600 'set baud rate to 9600
DEFINE DEBUGIN_MODE 1 'communicate in inverted mode

i var byte
char var byte

For i = 1 to 3
porta.5 = 0 'led on
pause 333
porta.5 = 1 'led off
pause 333
next

'user input with VT100 terminal

re: debugin [char]
debug char

goto re


The PIC echos back to the PC correctly. Double characters display as expected. Note that the transmission mode is inverted. I believe this mode is standard for RS232 communications. Also, I am using a null modem cable (Tx and Rx reversed ). I believe this is also standard. Haven't tried the radio link yet with this set up.. Any suggestions?
Dick

p.s. The DEFINES are capitals in the actual code. Not all show this way with the pasted code.

Demon
- 8th May 2013, 19:00
I'd type over the DEFINES in capitals. If you copy & paste from your code and they come out in lower case here, then it seems like your IDE is just displaying to you in upper case. They are still lower as far as PBP is concerned.

Robert

Ioannis
- 8th May 2013, 19:38
Since PIC to PC is working then I have three thoughts on this.

1. one or both modules are not working. You may try here to change the modules between them.

2. Settings are not the defaults

3. The feeds to the modules are reversed (tx to rx etc).

The modules need true mode and not the inverse you just tested with the PC. But I suppose you will change your code for this test.

Wish you luck, cannot see anything else now...

Ioannis

Dick Ivers
- 8th May 2013, 21:35
Hi all,

Working at last...... the problem was reversed Tx and Rx, just as Ioannis suggested above. I was misled by incorrect markings on the prototype board I got from Ciseco. Also, I corrected the define caps, although this did not seem to be a problem because the leds were blinking at the right speeds.... thanks for the tip Robert. You guys are very patient to stick through this ... I salute you. Final code here:


'************************************************* *************************
'*Program to test XRF radio communications via loopback method *
'*Uses a pushbutton switch on porta pin 4 *
'*Target processor is PIC 12f1822 *
'*207 program words, revised 05/08/2013 *
'*Program by Dick Ivers *
'*All rights reserved *
'************************************************* *************************
'set 12f1822 configurat1on
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CLKOUTEN_OFF & _WDTE_ON
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#endconfig

'set registers
OSCCON = %01111000 '16 mhz osc
OSCTUNE = 0 'factory calibration
ANSELA = 0 'all digital inputs
OPTION_REG.7 = 0 'global pullups enabled
WPUA = %010010 'porta pin 1 and pin 4 weak pullups enabled
CM1CON0.7 = 0 'comparator disabled
TRISA = %011110 'porta.0 & porta.5 are outputs, all others input

while OSCSTAT.0 = 0 'wait for stable freq.
wend

DEFINE OSC 16 '16 mhz oscillator


'Define debug parameters
DEFINE DEBUG_REGG PORTA 'set debug port to porta
DEFINE DEBUG_BIT 0 'use pin ra0 of porta for debug
DEFINE DEBUG_BAUD 9600 'set baud rate to 9600
DEFINE DEBUG_MODE 0 'communicate in true mode

DEFINE DEBUGIN_REGG PORTA 'set debug port to porta
DEFINE DEBUGIN_BIT 1 'use pin ra1 of porta for debugin
DEFINE DEBUGIN_BAUD 9600 'set baud rate to 9600
DEFINE DEBUGIN_MODE 0 'communicate in true mode

i var byte
char var byte

For i = 1 to 3
porta.5 = 0 'led on
pause 333
porta.5 = 1 'led off
pause 333
next

asleep:
nap 2 'delay 4 ms
if porta.4 = 1 then asleep

DT:
debug 55
debugin 100,blink,[char]
if char = 55 then
porta.5 = 0 'led on solid
goto halt
endif

blink:
porta.5 = 0 'led
pause 500
porta.5 = 1 'led off
pause 500
if porta.4 =1 then asleep
goto DT

halt:
stop 'led stays on

tasmod
- 9th May 2013, 11:01
Congratulations on sorting it Dick.

I'm having problems with my code which seems so simple but it won't work with serin/out2 qualifiers.

I have commented out the Serin2 ACK in the control code as it doesn't get one due to the field code not working. This way, at least the code works the relay ok if I remove the Serin2 qualifier and just send "BOB".
This points to the qualifiers as the culprit as without them the code works OK.

I've tried every combination and it doesn't respond. All I want in the Field unit is to receive a qualifier to branch to the desired gosub.

Please bear in mind code below is probably incorrect as it's what's left of trying.

Control code



Include "modedefs.bas"
DEFINE OSC 10

TRISA=%00000000
TRISB=%11110000
CMCON=7 ; comparators off

redled VAR PortB.4
greenled VAR PortB.5
yellowled VAR PortB.6
switch VAR PortB.7

redstop VAR BYTE
greengo VAR BYTE
flip VAR BYTE

;relay var PortA.1

flip = 0 ; counter flipflop for single command send

redstop = 1
greengo = 2


test: ; test led outputs
high redled
pause 500
low redled
high greenled
pause 500
low greenled
high yellowled
pause 500
low yellowled

pause 2000

main:

IF SWITCH = 1 and flip = 0 THEN GOSUB red
pause 500
IF switch = 0 and flip = 1 then gosub green

goto main

red:
pause 1
SEROUT2 PortA.3,T9600,["BOB",redstop] ; send command to field unit
;SERIN2 PortA.2,84,[WAIT("ACK")] ; wait for acknowledge signal
low greenled
high redled
flip = 1 ; flip flop counter to ensure send only once
gosub flash ; flash test led
return

green:
pause 1
SEROUT2 PortA.3,T9600,["BOB",greengo]
;SERIN2 PortA.2,84,[WAIT("ACK")]
low redled
high greenled
flip = 0
gosub flash
return

flash:
high yellowled
pause 50
low yellowled
PAUSE 50
high yellowled
pause 50
low yellowled
PAUSE 50
high yellowled
pause 50
low yellowled

return

END



Field code



Include "modedefs.bas"
DEFINE OSC 10

TRISA=%00000100
CMCON=7

relay VAR PortA.1

signal var BYTE

low relay



' Program
MAIN:

SERin2 PortA.2,84,[wait("BOB"),dec SIGNAL]

if signal = 1 then
gosub redstop
endif

if signal = 2 then
GOsub greengo
endif

goto main


redstop:
high relay
pause 25
SEROUT2 PortA.3,T9600,["ACK"]
return

greengo:
low relay
pause 25
SEROUT2 PortA.3,T9600,["ACK"]
return

END



As an oddball I also discovered that FOR NEXT just doesn't seem to work in any of my codes?

Rob

Ioannis
- 9th May 2013, 12:18
Your Pause 25 may be is too short. Try a longer delay. Say 1 second.

Also please do the check list as Dick did in post #23.

Also test if direct connection of your two PIC works as expected.

Ioannis

tasmod
- 9th May 2013, 12:29
Hi Loannis,

Thanks for the help.

I changed the pause to 1 second but it made no difference. It doesn't move on past the Serin unless I remove the 'DEC signal' part so it doesn't reach the Sub.

I removed the variable parts of the Serout/In and it will work as a one shot. Add a DEC anything and it won't receive it.

So Field receives "BOB" and will fire relay if I comment out the 'if then' and add a HIGH relay but will not work on a variable value.

Oh yes, I'm just testing direct connections at moment. When it works as expected I will add the modules.

I noticed the post of the code had odd formatting, some caps, some lower case. Strange as this was done with Microcode Studio. Just to be sure I copied it into Notepad and wrote the commands as necessary in capitals. No change when compiled, didn't work. I thought the odd 'SIGNAL' in caps was causing a problem. It wasn't written in caps.

Rob

Ioannis
- 9th May 2013, 12:48
WelL I missed that.

You DO NOT HAVE to place the DEC modifier since what you send is just a binary number.

So discard the DEC from your SERIN and you will be OK.

Ioannis

tasmod
- 9th May 2013, 13:07
OK as you can guess I'm at the pc doing the programming right now.

I'm sending SEROUT2 PortA.3,T9600,["BOB",redstop] where variable redstop is allocated redstop = 1

on the other unit ---

I'm trying to receive SERIN2 PortA.2,84,[WAIT("BOB"),signal] to put the received value into variable 'signal' .

If signal =1 then gosub

Whatever combination I try, straight or DEC it doesn't respond.

Am i doing something stupid?

Rob

Ioannis
- 9th May 2013, 13:32
1. Serout2 and T9600 are not compatible. Use 84 instead.

2. Are you sure of the correct ports and connections? Try it directly from PIC to PIC.

Ioannis

tasmod
- 9th May 2013, 13:46
Yesssss. That was it !

Read the manual so many times I was confused over what worked with what. Changed to 84 and it works.

Thank you Loannis

Ioannis
- 9th May 2013, 13:49
Glad you got it.

It is a good feeling when it works, isn't it?

Ioannis