40X1 to 28X1 serial comms

Parramatta

New Member
G'day,

I have been searching, in vain, for a solution to my problem. I'm trying to send info from a 40X1 to a 28X1 using serout/serin. My ultimate aim is to produce a telemtry system using a 9600 Bps RF modem, displaying on a serial LCD.

I can display what I want using hserout out 57600 Bps on the LCD from either PICAXE however when I try to serout from the 40X1 to serin on the 28X1 I have problems. There is comms, however what I receive is different to what I transmit.

I have attached the programs I am trying, B2B is the PICAXE to PICAXE and B2LCD is PICAXE to LCD.

Any help would be greatly appreciated!!

Jesse
 

Attachments

Your Problem:

Picaxe 1 (40X1) is sending to Picaxe 2 (28X1)

Sends "200" in ASCII characters to Picaxe 2 (28X1), (because # is used)


Picaxe 2 (28X1) only has a byte -> OH NO! -> "2" is put into b0 and "00" is discarded.

ASCII "2" is the same as 50 numric.

Picaxe -> LCD

Sends 50 in ASCII (because # is used).

LCD Shows 50.

Solution:

Replace in Picaxe 1 (40X1) code:

serout 0,n9600_8,(b0)
 

Parramatta

New Member
Thanks for that.

I had read other threads that did indicate that may be a problem (the number of bytes). You're correct, the LCD does display 50 or something similar. I was intending to send "200" though. I will eventually need to send a number representing eng. RPM and the like from a UAV for display on a ground control panel. If the rpm is going to vary from 0 - 10000, how can I send this info?

Thanks again
 
If you want to be sending a value between 0-10000 then use w0 instead of b0.

incase you didn't know:

a byte can hold a value from 0-255
a word can hold a value from 0-65535
 
Try This

B2LCD

Code:
setfreq m8

pause 500

hsersetup b57600_8, %01

hserout 0,(186)					'Clear Screen

main:

debug

gosub setup

gosub EngRPM

gosub RotRPM

goto main

setup:	
	hserout 0,(127,"Eng RPM:",255)	'Set cursor position and write text to LCD
	pause 30
	hserout 0,(129,"Rot RPM:",255)	'Set cursor position and write text to LCD
	pause 30
	return
	
EngRPM:
	serin 7,n9600_8,b0,b1		'Read value into w0
	hserout 0,(127,144,#w0,255)		'Set cursor and write w0 to LCD
	pause 30
	return
	
RotRPM:
	hserout 0,(129,144,"800",255)		'Set cursor and write w0 to LCD
	pause 30
	return
B2B

Code:
pause 100

setfreq m8

let w0 = 98765

main:

debug

pause 1000

serout 0,n9600_8,(b0,b1)  

goto main
Should return 98765


*EDITED*
 
If you want to be sending a value between 0-10000 then use w0 instead of b0.

incase you didn't know:

a byte can hold a value from 0-255
a word can hold a value from 0-65535
 

Parramatta

New Member
Thanks again mate, this seems to be working. However to transfer at 9600 I have needed to use a 16 MHz crystal, when I use this cystal the hserout no longer seems to work. Is there a clocking down compensation I need to use, at the moment I'm using hsersetup b57600_16, %01?

The problem with the value is not the size (0-255) but that I'm sending it as a character. I need 1 byte for every character and if the length changes ie 2000 then 500, the serin command will wait because it will be expecting a 4th byte. Will a timeout solve this issue?
 
1. don't forget to use setfreq command at the beginning of software.

2. I'm not sure, try yourself, I've never done picaxe to picaxe communications.
 

hippy

Ex-Staff (retired)
I've merged the thread from Software Feedback with this one

Duplicate postings and links to the other thread deleted.
 
Last edited:

Parramatta

New Member
I am using the setfreq em16 command and the picaxe's are talking however when I try to send to the LCD I get corrupt info.
 

hippy

Ex-Staff (retired)
Is the correct Nxxxx_y/Txxxx_y baud rate being used and is it right for the LCD ? is it the AXE033 LCD Module you are communicating with or something else ? What's the specific code you're using to send data ? Does it not work from the 28X1, the 40X1 or both ?
 

Parramatta

New Member
G'day hippy,

I'm using the Serial Graphic LCD 128x64 DX160-G from Sparkfun electronics at 57600 baud. When using either the 28X1 or 40X1 at 4 or 8 MHz it works fine using hserout 0,57600(_8 when at 8 MHz), however when using the 16 MHz crystal I get corrupt info using hserout 57600_16. I have used setfreq em16 before main. Any ideas?
 

hippy

Ex-Staff (retired)
For "HSERSETUP <baud>,<mode>" the <baud> is simply a number which is poked to the on-chip baud rate register; "SERTXD( #B57600_8 )" and similar will show the values. I get ...

B57600_4 = 16
B57600_8 = 34
B57600_16 = 51

In the 16F886/7 datasheet, table 12.3 shows how to calculate what the number should be to get a particular baud rate and vice-versa what a baud rate is for a particular number. The numbers will normally be ( but not exactly ) doubled for every doubling of clock frequency, and 51 looks well out of step in that for 16MHz. I suspect the pre-defined constant has the wrong value.

From my calculations I get 68, so you could try "HSEROUT 68,<mode>". You may have to tweak the 68 up or down a bit. Reduce it until it stops working, check 68 is still working, then increase until it stops working. The mid value is the ideal one to use.
 

Parramatta

New Member
Success

Thanks very much hippy, that worked a treat. Why doesn't the manual give the alternate variation of the hsersetup command. When using an external resonator hsersetup 57600_16 %01 does not work however hsersetup 68 %01 does!! this lead to a lot of frustration. Alls well that ends well I supose. Again, thanks every one for the help.
 

hippy

Ex-Staff (retired)
Why doesn't the manual give the alternate variation of the hsersetup command.

Primarily because it's not necessary and could be confusing. The only problem in this case that the value for 57600_16 was wrong and I'd expect it to be fixed in the next release of the Programming Editor. I'll post in Software Feedback to make sure the problem is noted by Technical if they haven't fixed it already.
 
Top