Serial data problem

JayAuckland

New Member
I'm intending to eventually use a 14M2 chip to poll several switches (and possibly a potentiometer) and output a qualifier and value to show when each switch is pressed or not, sending the data down a serial line to several 'receiver' 14M2 chips.

For the moment I'm getting my head around it by breadboarding it using an 08M2 chip to poll the switches and this code:

Code:
setfreq m4
Input c.2

Pollsw4:
If pinc.4 = 1 then
serout C.1,N4800_8,("SW4",1)	
goto pollsw3 
else 
serout C.1,N4800_8,("SW4",0)
goto pollsw3
endif

Pollsw3:
If pinc.3 = 1 then
serout C.1,N4800_8,("SW3",1)
goto pollsw2 
else 
serout C.1,N4800_8,("SW3",0)
goto pollsw2
endif

Pollsw2:
If pinc.2 = 1 then
serout C.1,N4800_8,("SW2",1) 
goto pollsw4 
else 
serout C.1,N4800_8,("SW2",0)
goto pollsw4
endif
I'm feeding the serial out data currently to just two chips, an 08M2 and a 14M2 (the only 14M2 I have at the moment) but i intend using all 14M2 chips when i build this up.

The 08m2 'receiver' chip and code works fine, inputting the serial data and responding to switch 3 by flashing an led.

Code:
setfreq m4
disconnect

Poll:
serin 5, N4800_8,("SW3"),b6	  'input switch 3 status into variable b6

if b6 = 1 then
goto flash
else
pause 20
goto poll
endif

flash:
high C.1
pause 200
low C.1
pause 200
high C.1
pause 200
low C.1
pause 200

goto poll
However, the 14M2 chip is not responding, either when I try to get it to input one of the other switches' status or even when I 'parallel' it by setting it to input switch 3 - which the 08M2 responds to just fine.

14M2 'receiver' code:

Code:
setfreq m4
disconnect

output B.1

Poll:
serrxd c.5 ("SW3"),b6	'input SW3 status into variable b6

if b6 = 1 then
goto flash
else
pause 20
goto poll
endif

Flash:
high b.1
pause 200
low b.1
pause 200
high b.1
pause 200
low b.1

goto poll
I guess I'm somehow getting tangled up around the serin and serrxd syntax stuff or maybe the 08M2 and 14M2 chips operate in slightly different ways?

Help!!!
 

Technical

Technical Support
Staff member
The 08M2 is probably not doing what you think it is, as you are using N4800_8 at 4MHz = 2400.
 

JayAuckland

New Member
So it's a frequency thing maybe? Cool, I'll have a play with the frequencies etc. of the chips and see what I can come up with... perhaps find a way to slow the 14M2 down to the 08M2 speed, or perhaps I should just wait a week or so until I can get more 14M2 chips so everything's consistent.

Tks Technical!
 

hippy

Technical Support
Staff member
So it's a frequency thing maybe?
Probably a baud rate and frequency mismatch. You are specifying N4800_8 which is a baud rate when running at 8MHz but you are running at 4MHz.

If using SERRXD on the 14M2 at 4MHz (default) that expects 4800 baud. You therefore need to send at N4800_4 baud.
 

inglewoodpete

Senior Member
... perhaps find a way to slow the 14M2 down to the 08M2 speed.
The 14M2 and the 08M2 are practically identical when it comes to speed of execution.

As an aside, you have a lot of redundant code there. The PICAXE is actually quite a cleaver beast. You could do the some thing, many times faster with the following code. Of course, you may find that the receiving end can't keep up!
Code:
[color=Blue]SetFreq M4
Input C.2, C.3, C.4

Do
   SerOut C.1[/color][color=Black],[/color][color=Blue]N4800_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"SW4"[/color][color=Black], [/color][color=Purple]PinC.4[/color][color=Blue])
   SerOut C.1[/color][color=Black],[/color][color=Blue]N4800_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"SW3"[/color][color=Black], [/color][color=Purple]PinC.3[/color][color=Blue])
   SerOut C.1[/color][color=Black],[/color][color=Blue]N4800_8[/color][color=Black],[/color][color=Blue]([/color][color=Red]"SW2"[/color][color=Black], [/color][color=Purple]PinC.2[/color][color=Blue])
Loop[/color]
 

JayAuckland

New Member
Thanks hippy, baud rates etc. are a new thing for me so it's great having you guys holding my hand as I stumble into it!

Thanks also inglewoodpete... as my programming knowledge isn't great (or intuitive) I'm still tending to use pedantic, simple stuff that's based on the few elements I've learned so far which at least does the job even if it's not very elegant. But your suggestion is really cool, I would never have thought of doing the job in such a classy way!

J.
 
Top