4- 08's talking serial

tmack

Member
I am attempting to have 2 08's send serial 1-4,5-8 respectively to 2 other 08's that will decode it and turn leds on.I am trying to do this using only 2 wires. So I have 2 08's sending the data. I have completed the code for the 08's and they are working fine.Now I am just at the point of connecting them both to my DB9 connector then my sending unit willbe done.I put a 4148 diode on the line out coming from each 08 to keep the signal away from the other 08 that will also be sending data.My data is not making it past my diode. On the 08 side my sender is working fine but on the other side of the diode the signal is not there. I have the polarity of the diode correct and have checked it the other way just to be sure.Do I need the diodes there in the first place? I saw it on a webpage somewhere. Both 08s are sending data on the same wire.The first is sending "1","2","3","4" the second is sending "5","6","7","8" out on the same line so that my decoding 08s will be able to decode the 1,2,3,4,5,6,7,8. Im not sure what will happen if the pin on my second 08 gets the data from my first 08 both in the sending unit because they are communicating over the same wire. I hope this wasnt too confusing. Its hard for me to explain sometimes.Thanks for any help.
 

BeanieBots

Moderator
Ok, I think you are trying to send data from more than one PICAXE sender to the same PICAXE pin on one receiver.
If that is correct, then you do need the diodes.
If you have the pointy ends towards the receiver, then the receiver pin must also have a pull-down resistor.
If you have the pointy ends towards the sender, then the receiver must have a pull-up resistor.
Which way you should have the diodes is determined by if you are using true or inverted comms. Sorry, can't remember which needs which but it must be the right way or the one not sending will hold the line and make it impossible for the other to send. That is what it sounds like is happening in your case.
 

tmack

Member
AH HA!

I put a 10k resistor between the ground and the pointed end of my diodes and Now it works. Thanks Beanie!
 

lbenson

Senior Member
This probably explains why I couldn't get the two-picaxe (lacking hserin) method of getting a response from the Simplelan module to work several months ago.

Is it correct to put it this way: when using a wired-or for serial communication (true signals) it is necessary to put a pull-down resister between the diode (pointy-end) and the receiver pin?
 

BrendanP

Senior Member
Lucky I read this I'm drawing up a pcb to take 3 X 40X1's that have the serially communicate. I didnt realise I needed the diodes and r's. Thanks guys.
 

inglewoodpete

Senior Member
Brendan, Always test a hardware configuration on a breadboard before designing and making a PCB.

How do I know? I'm currently redesigning a PCB for a project where I half-tested the hardware on a breadboard before committing the a PCB design! It seemed so simple at the time that I didn't fully test my circuit concept....
 

BrendanP

Senior Member
Yep, I've spent about $2,000 at my friendly local pcb maker demonstrating the truth of that statement.
 

tmack

Member
Update

I have it all up on breadboards working pretty well. However, The leds are flashing quickly instead of just coming on steady. If I check the circuit Before the diodes seperately The leds are on steady. So I have to believe that my diode resistor set up isnt quite right. I am going to perform a test by changing out the resistors to hopefully find one that works correctly. Does anyone know how to find the correct value resistor other than by trial and error. I am using a 10k now. Thanks.
 

tmack

Member
hmp

I switched my resistor and can't seem to get it to work right. It is definately in the last portion of the circuit.Before the diodes ,it's working great . After the diodes/resistor the signal is making them flash. Any thoughts?
 

hippy

Technical Support
Staff member
Sounds to me that the input you are driving into my be an output. Disconnect the PICAXE(s) being communicated to and see if the Leds then behave the same on each side of the diode. If not then something is wrong with your circuit but I'm not sure what, possibly 0V isn't 0V.

The voltage drop across the diode is about 0.6V so you should be able to use the same value R either side. What value R ? Depends how bright you want your Led and what it takes to kick it into lighting up. I use 1K8's, others use 330R.

I'd suggest stripping your circuit down to just one sending PICAXE. Get that working so it's the same on both sides of the diode. Add the second sender and check that the Led on the receiver side of the diode is on when either of the sender Led's are on. Then add one receiver, get that working, then add the next.

I'd add and leave Led's on the two outputs and the two inputs, then you have easy visual confirmation of what's going on at all times. They shouldn't interfere with the data transfers.
 

BeanieBots

Moderator
I'd add and leave Led's on the two outputs and the two inputs, then you have easy visual confirmation of what's going on at all times. They shouldn't interfere with the data transfers.
If you are going to do that, don't use 330R resistors. That amount of loading (particularly after a diode) may well interfere with the comms.
Use a 1k8 or even 2k2 with the LED, it will easily be bright enough to see.
As for the 'general' pull-up/down value, anywhere between about 2k2 and 47k should work perfectly well. 10k is a popular choice because it is a common value and human nature likes simple round numbers.
 

BrendanP

Senior Member
Can I have the three inputs of the three 40X1's all joined together on the same track

I need some help guys.
I understand I need the diodes and r's as explained above.
I have three 40X1's that need to serially communicate amongts themselves. Can I have the three inputs of the three 40X1's all joined together on the same track? This would then mean that the 'talking' IC would be 'talking' into its own input. Is this a problem?
 

moxhamj

New Member
No problem with talking to your own input. If an input is configured as an input (in code) then it will have a high impedence. You can connnect as many inputs in parallel as you like. The code will listen to those inputs when you tell it to. You might hear your own input but that wouldn't happen in code and even if it did, the messages would have headers indicating which chip the message is for.
 

BrendanP

Senior Member
Thanks Dr. I was concerned that I would get short circuit type situation but your calm bedside manner has calmed my racing pulse yet again......

One more query, do I need to put a pull down R next to each input or, as I suspect, will one pull down R for the track that joins all the inputs together suffice?
 

tmack

Member
Im confused

I had to change my info because I lost my password. So I guess Im no longer tmack. Anyhow, I am confused.Let me start by saying both sending 08s are working correctly independantly. When I have my first sending 08 going through my diode/10K resistor it works fine. When I add my second signal to the mix through its diode then the result is that the leds on the reciever flash quickly instead of coming on steady. My reciever is working fine because I checked it using a VBasic program I wrote to check it. I am wondering if it is in my code somewhere. Even though they work ok independantly when they are put together are both of my 08s sending the "0" out in a way that is making the ld turn off while the other 08 sends it a "1" or whatever to turn on therby making it flash? Or is it just a problem like I thought before with just my led/diode part? I have to figure out where to go from here.
 

tmack

Member
Heres my code:

Sender 08 #1:

Do
b0 = "0"
If pin4 = 1 Then : b0 = "4" : End If
If pin3 = 1 Then : b0 = "3" : End If
If pin2 = 1 Then : b0 = "2" : End If
If pin1 = 1 Then : b0 = "1" : End If
SerOut 0, N2400, (b0)
Pause 100
Loop


Sender 08#2:

Do
b0 = "0"
If pin4 = 1 Then : b0 = "8" : End If
If pin3 = 1 Then : b0 = "7" : End If
If pin2 = 1 Then : b0 = "6" : End If
If pin1 = 1 Then : b0 = "5" : End If
SerOut 0, N2400, (b0)
Pause 100
Loop
 

tmack

Member
I am definately thinking its my code now that I look at it together. i think I have to change my "0" on the second 08 to another # so the first and second 08s are not sending out "0" I think thats where my flashing is coming from.
 

tmack

Member
GOT IT!

That was it , it was my code. I had the two 08 senders sending "0" when no switch was depressed. So when one 08 had a switch depressed and was sending out its character the other 08 still didn't have its switch depressed so it was still sending out a "0" and making the receiving 08 blink on and off. I just switched the second sending 08 and receiving 08 to use a "9" instead of also using a "0" and we're in business.
Just a question though , How come I can't use a "10" for a character? It says there is an error in that line if I put anything over a "9". I am guessing I can use a "a"- "z" if I want to add more but I'm curious why I cant use a "10", "11" or "12".
Thanks for all you help.
 

hippy

Technical Support
Staff member
You also do not have any synchronisation so any slight drift and each may eventuually start sending while the other is, both corrupting what the other sends. The receiver will find it hard to know what is going on and may start behaving strangely - a bit like seeing that flickering Led.

Why can you not send "10" ? Because it's not a single character. When you send a single character it is sent as a number which represents that character. By agreement ( ASCII ) defines what those numbers mean when it comes to converting what's typed on a keyboard, what's held in memory and what's shown on the monitor.

Sending "0" actually sends a byte of hex value $30, "1" is $31, "A" is $41, "Z" is $5A

If you want to deal with things in quotes, you have to use single letters and digits, not multiple letters or digits. If you want to send raw numbers, that works just as well and you can then send one of 256 possible numbers $00 (0) to $FF (255).

Your sender can use ...

- If pin1 = 1 Then : b0 = $01 : End If
- If pin2 = 1 Then : b0 = $02 : End If
- If pin3 = 1 Then : b0 = $03 : End If
- If pin4 = 1 Then : b0 = $04 : End If
- SerOut 0, N2400, (b0)

Your receiver would use sonething like ...

- Setin 1, N2400, b0
- If b0 = $01 Then Gosub Pin1WasHigh
- If b0 = $02 Then Gosub Pin2WasHigh
- If b0 = $03 Then Gosub Pin3WasHigh
-If b0 = $04 Then Gosub Pin4WasHigh

Now we're sending numbers, the 'pins' variable is a number, made from input bits so you could pass that number over in one go ...

- b0 = pins & %00011110 ' Keep only pin4..pin1
- SerOut 0, N2400, (b0)

- SerIn 1, N2400, b0 ' Also sets bit7..bit0
- If bit1 = 1 Then Gosub Pin1WasHigh
- If bit2 = 1 Then Gosub Pin2WasHigh
- If bit3 = 1 Then Gosub Pin3WasHigh
- If bit4 = 1 Then Gosub Pin4WasHigh

The only down-side to sending raw numbers rather than letters in quotes is that not all Terminal Emulators will display the raw numbers. Things like $0D and $0A likely do not get displayed at all but show as a carriage return, line-feed, others will display as meaningless characters.
 

tmack

Member
Syncronization, Raw numbers

How would I go about adding synchronization?

So If I wanted to send raw numbers I could use $00=0 through $99=99? Am I right in assuming that ?($99=99)If so thats plenty of numbers to use but just for curiosities sake, how do I figure out what would come after $99. I can't find any reference material for it.
 

hippy

Technical Support
Staff member
Synchronisation : That involves one telling the other it can do something and being told back when it has finished so it can do something itself. The usual method is to run two lines in opposite directions between the two and each monitors the levels of the other's line. Usually one is designated a master to it decides when the other can run. It is possible to have just a single line ( "your turn now" ) providing the initiator waits long enough for the other to finish before sending itself.

Raw numbers : $xx are hexadecimal numbers, base-16; $00=0, $09=9, $0A=10, $10=16 and so on, so $99=153, $9A=154 follows that.

Google or Alta Vista is probably the best source for an explanation on various number forms and bases. I don't have any particular recommendations myself I'm afraid.

This lot - http://www.intuitor.com/hex - claim base-10 "is a holdover from the Dark Ages" and we should all convert to hexadecimal in everyday life. Although they show counting on fingers is suited to base-10, base-6, and base-2 there's a distinct lack of any evidence for an inherent ability to use base-16 :)

For the rest of us not so convinced, the main use of hexadecimal is to bridge the boundary between binary ( where each bit being on or off indicates some particular significance - particularly when a bit representing a setting in a register or an I/O line of a port ) and decimal where bit significants is not clear. Hexadecimal simply groups binary in sets of four bits making numbers shorter and easier to comprehend.

Example to set Output Pins 6 and 3 of a PICAXE, all the following do the same, but some intentions are clearer than others -

- pins = %01001000
- pins = $48
- pins = 72
 
Top