Serout with Picaxe 18x and Serin with Picaxe 20x2 problem!

hugoxp1

Member
Hi,


I am trying to send serout command from a 18x Picaxe and receive with serin command in a 20x2 picaxe.


this is the code in 18x Picaxe:

Code:
main:


	for b0 = 0 to 255
		
		'-blink led to see when serout is executed
		high 3
		
		
		'--commands to make serout work better (without sending corrupt data)
		high 2 
		pause 3 
		low 2 
		pause 1 
		
		
		serout 2,N4800, ("AA")
		
			
		
		low 3
		
		
		pause 2000
		
		
	next b0



goto main

and this is the code that i have in my 20x2 Picaxe:


Code:
#No_Data

'--change frequency to 4Mhz
setfreq m4


'--set PortB as output
let dirsb = %11111111



main:


	serin C.2, N4800, b0,b1
	
	

	sertxd ("Result: ", 9, #b0, 9, #b1, CR, LF)
	pause 20
	
	
	
goto main

And the only thing that i can visualize with the sertx command is:

Result: 0 16
Result: 0 16
Result: 0 16
Result: 0 16
Result: 0 16
Result: 0 16
Result: 0 16
Result: 0 16
(...and continues)



can you help me please to figure out what's wrong?
I was waiting to see:

Result: A A


Thank you
 

MPep

Senior Member
Code:
#picaxe 20X2
#No_Data

'--change frequency to 4Mhz
setfreq m4


'--set PortB as output
let dirsb = %11111111

main:
     serin C.2, N4800, b0,b1
    sertxd ("Result: ", 9, b0, 9, b1, CR, LF)
    pause 20
goto main
This should do what you want. Removd the # in the SERTRD. Hope this helps.
MPep.
 

hippy

Ex-Staff (retired)
The 18X is okay, it's the 20X2 which is the problem ...

SetFreq M4
SerIn C.2, N4800, b0, b1

The N4800 baud is only correct at the default 20X2 frequency (8MHz). If you drop to 4MHz you need to use N4800_4.
 

hugoxp1

Member
Strange thing....

After i made some changes (based in your help), this is what I achieve:


18x PICAXE code:

Code:
main:


	for b0 = 0 to 255
		
		'-blink led to see when serout will be executed
		high 3
		
		
		'--commands to make serout work better (without corrupt data)
		high 2 
		pause 3 
		low 2 
		pause 1 
		
		
		serout 2,N1200, (85,85,"Hello world")
		
			
		
		low 3
		
		
		pause 2000
		
		
	next b0



goto main


PICAXE 22x2 code


Code:
#No_Data


[B]'---8mhz[/B]

'--PortB as output
let dirsb = %11111111




main:



	serin C.2, N1200, (120,213,85), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10
	


	sertxd ("Result: ", 9, b0, 9, b1,9, b2,9, b3,9, b4,9, b5,9, b6,9, b7,9, b8,9, b9,9, b10,9,CR,LF)

	pause 20
	

goto main

And as result of the sertxd command i have:

Result: H e l l o w o r l d
Result: H e l l o w o r l d
Result: H e l l o w o r l d
Result: H e l l o w o r l d
Result: H e l l o w o r l d
Result: H e l l o w o r l d
Result: H e l l o w o r l d

(...and continues)

what I can't understand is:
if the code in 18x Picaxe sends (85,85), why the 20x2 picaxe always "transform" to (120,213,85)???


well... as you can see, it works, but i would be better if i could understand my last question!


thank you a lot!
 
Last edited:

westaust55

Moderator
My first thought would be to remove the lines
'--commands to make serout work better (without corrupt data)
high 2
pause 3
low 2
pause 1


The inverted Serout has the data line idling low but then you add the line
pause 3 to make the SEROUT pin high for 3 millseconds and maybe a fraction longer as the commands execute.
That equates to 3 or 4 bits in the "1" / high state.
Then the Pause 1 equates to 1 or 2 "0" / low bits and maybe an extra one while the code is interpreted.

Looking at the data you have
120 = %0111 1000
213 = %1101 0101 ; this is almost "85" just 1 bit wrong
85 . = %0101 0101



One further suggestion, why not have an alias for the ASCII tab code
SYMBOL TAB = 9​
then the Sertxd line become much more readable as:
sertxd ("Result: ", TAB, b0, TAB, b1,TAB, b2,TAB, b3,TAB, b4,9, b5,TAB, b6,TAB, b7,TAB, b8,TAB, b9,TAB, b10,TAB,CR,LF)​
 
Last edited:
Top