word variables - only needs 1 short reply :)

alband

Senior Member
I have a 08M deciding wether two inputs are on.
It then tells a 28X1 which is on (only one will be on at a time).
The 28X1 then displays this info on an LCD.
Currently both chips are chatting merrily via serout/in.

What I want to know is why when I send ("1") the other chip picks it up as 204.
Also is it possible to send words and can w0, w01, etc hold words or only numbers 0-65335.
Therefore if I want to send: "hello" from one chip to another do I need to turn hello into a number then change it back at the other end.

Thanks in advance,
David
 

BeanieBots

Moderator
If you send "1", you should get 49. ie $31 or "1".
Why you are getting 104, ("h") I really don't know. Can only guess a baud rate or inversion problem. Can't see anything obvious about the bit pattern but sombody else might.

You can only send one byte at a time using serout. It is not possible to send a word value as single entity.
You could either send the two bytes seperately serout,pin,baud,(b0,b1) or you could convert to ascii and send the individual digits serout,pin,baud,(#w0). The latter might be a problem because you will get a different number of characters depending on what the number is.
 

alband

Senior Member
Currently...

DISPLAY.bas is 28X1, out3 is to 08M, out4 is LCD in7 is from 08M
target emplier.bas is 08M, out2 is to 28X1, in3 is from 28X1, in1&4 are phototransistors(I know are working with PICAXE)
 

Attachments

moxhamj

New Member
Could you post a schematic as well please? You mention phototransistors -are these between the two chips? I'm having to guess here, but I wonder if the inversion from a phototransistor is the problem. 204+49 is very close to 255, and it could be if there was an inversion in there and a bit at one end got missed.
 
Last edited:

alband

Senior Member
Nope, nothing to do with photototransistors (PTR) overflowing. They are both connected to the 08M from VDD to input pin with a 22K tying the pin low.
I've currently got the circuit working. The 08M sends either "1" or "2" for each PTR or "0" if neither is triggered. That is recieved as
Code:
serin 7,T2400,b1
and then displayed as
Code:
serout 4,T2400,(254,128,"Target ",254,192,"number=",#b1)
This is working fine but I want to send words from the 08M to the 28X1 and then simply diplay those e.g.
Code:
serin 7,T2400,w0
serout 4,T2400,(254,128,#w0)
 

alband

Senior Member
So if I wanted to send the word "GR 01,01".
I would have to,
Code:
serout pin,T2400,"GR 01,01"
and
Code:
serin pin,T2400,b0,b1,b2,b3,b4,b5,b6,b7
Then b0 = G, b1=R, b2= ,b3=0 etc.
 

Technical

Technical Support
Staff member
Yes, but as things get more complicated you may want to send a special 'qualifier' character to make sure everything is always correctly synchronised. For instance if you choose "?" as a qualifier

serout pin,T2400,"?GR 01,01"
serin pin,T2400,("?"),b0,b1,b2,b3,b4,b5,b6,b7
 

Jeremy Leach

Senior Member
Think I'm on the right track, but not 100% sure...

In you Display.bas code you set out3 to low before doing any serouts on out3. But using 'T' qualifier means 'idle high', so you should set this line high before the serouts.

This is the data stream that should be received by the 08M in order to successfully receive "1" (Decimal 49). The rightmost is received first:
Code:
...| 1  | 1  | 0  | 0  | 1  | 1  | 0  | 0  | 0  | 1  | 0  | 1  | 1  |.....
   |IDLE|STOP|Bit7|Bit6|Bit5|Bit4|Bit3|Bit2|Bit1|Bit0|STRT|IDLE|IDLE|.....
So in proper use the 08M would be running it's serin (with the T qualifier) and so the idle state of In3 should be high, and it's waiting for the transition of high to low to mark the beginning of the start bit. Once the start bit is received it gets the 8 bits of the byte value being transmitted, then receives the STOP bit, which is a high.


BUT, if you are letting In3 idle low, then when you issue the Serin, the line is already low, so the serin keeps waiting for a high to low transition to mark the beginning of the Start bit. If you are sending "1", then the data stream into the 08M will be this ...
Code:
...| 1* | 1  | 0  | 0  | 1  | 1  | 0  | 0  | 0  | 1  | 0  | 0  | 0  |.....
   |IDLE|STOP|Bit7|Bit6|Bit5|Bit4|Bit3|Bit2|Bit1|Bit0|STRT|IDLE|IDLE|.....
And you can see that actually bit1 will be interpreted as the start bit instead. So the next 8 bits will be...
Code:
...| 1* | 1  | 0  | 0  | 1  | 1  | 0  | 0  |.....
This is 204.
However, note * : I'm assuming that after the stop bit has been transmitted, the line stays at the stop bit level. I'm not sure about this though. I'm not sure if the serout code returns the line to the original state, or just leaves the line at stop bit level. If the original state of the line is high then there would be no difference. I think that the fact that you are receiving 204 shows that the serout leaves the line at the stop bit level. If this is true then I'd expect your next Serin to receive "1" properly because the line is starting at the correct level !

(If this is right, then I predict that if you send "2" you will receive 230, or 11100110)
 
Last edited:

alband

Senior Member
That pin has just been set low to help me see what's going on. I've put LED on the serial lines to see if they are sending or not, allong with a few debugs helps to see whats going on. When the programs starts these pin are high for some reason so I cant tell when the serout comand has be passed. I put it low so I can se when the serout actualy happens.
 

BeanieBots

Moderator
I think Jez has point about the idle state.
If you still want LED indication, simply wire the LED the other way.
ie, between 5v and the I/O pin instead of 0v and I/O pin.
 

Jeremy Leach

Senior Member
The idle state definitely needs to be high if you're using T. So much for the 1 short reply :) I think it shows though that to solve some of these problems you need to be very clear on explaining the setup in order to get a short answer. I'm not assuming we've cracked it yet though - but possibly. You seem to have a good grasp of a lot of it.
 

alband

Senior Member
It's the basics that fog me.
"I can move the mouse with two pots, yet I know not of a variable" :rolleyes::)
Thanks for all the help. I'll try it soon but am swamped with work at the mo:D
 

alband

Senior Member
Well...
I've tryed it and use "debug" lots. It seems to be recieving the date allright but when I display the variables:
Code:
serout 4,T2400,(254,128,#b2,#b3,#b4,#b5,#b6,#b7,#b8," ",254,192,#b9,#b10," ",#b11,#b12,#b13)
It is displaying numbers.
I'm not good on variables. Can a bxx variable only be a number but than number can be code for a letter? It is showing the correct letters in the debug window but it is displaying the numbers.
How do I get it to dissplay the numbers as letters.
Here is the code for this section:
08M:
Code:
main:		
		low 2
		serin 3,T2400,b0
		debug b0
		if b0 = 204 then label_2
		if b0 = 84 then label_3
		goto label_1
		
label_2:	serout 2,T2400,("1")
		goto main

label_1:	high 1
		pause 500
		low 1
		serout 2,T2400,("0")
		goto main

label_3:	if pin1 = 1 then label_4
		if pin4 = 1 then label_5
		serout 2,T2400,("Missed!     ")
		goto label_3
		
label_4:	serout 2,T2400,("Hit!   GR1,1")
		goto label_3
		
label_5:	serout 2,T2400,("Hit!   GR2,2")
		goto label_3
28X1 Just the needed bits not whole file!
Code:
label_69:	serin 7,T2400,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13
		debug b2
		debug b3
		debug b4
		debug b5
		debug b6
		debug b7
		debug b8
		debug b9
		debug b10
		debug b11
		debug b12
		debug b13
		serout 4,T2400,(254,128,#b2,#b3,#b4,#b5,#b6,#b7,#b8," ",254,192,#b9,#b10," ",#b11,#b12,#b13)
		goto label_69
 
Last edited:

alband

Senior Member
I've now got it working!
Took out all those #'s adn it displayed the letters. The problem was, is that most of the time the variables didn't go where I wanted them to. They all got sent but to the wrong b'number.
Thanks for the answer Tech; Used the qualifier and it worked.

Thanks for the help everyone!
This thread has gone on way longer than the titel surgests but has been useful as ever.:D
 

Jeremy Leach

Senior Member
Glad it's working. I find threads spark off other ideas anyway, and the original question sometimes becomes irrelevant :D. (For instance, this thread has got me thinking it might be an educational little project to simulate Serin and Serout in code using bit-banging between two picaxes - ok, low baud rate but it would demonstrate the principle of asynch comms nicely, and be a nice little coding project in itself).
 
Last edited:

alband

Senior Member
In you Display.bas code you set out3 to low before doing any serouts on out3. But using 'T' qualifier means 'idle high', so you should set this line high before the serouts.
I'm now "in" another thread (X40 Big easy) where I am communicating these same two chips but with one serial line (explained in thread).
I'm having trouble and was wondering if this idle high thing is to blame.
If "T" means idle high, is it possible to set an idle low?
If possible post replys in the 40X big easy thread.
;)
 
Top