Serial Communication Confusion

alband

Senior Member
I have two 40X's talking to each other via two wires (common ground and serial line set up as per hippy's website) They are running happily of a wall wart and 7805 combo. They each have there own chip supplied by the wall wart (12V). When they are working they will be on different power supplies (hence the common GND line). I also have an LED across the serial line to GND to show the communication).

Attached is the code. Both pieces are long, but there is just one bit that needs zoning in on. In the "Display" code, it is line 326 and in "target empiler" is is the interrupt.

The communication should go like this:
"Display" sends a pulse (line 329) to interrupt the "target".
The "target" reads the serial data sent by the display. If this data = "1" then it sends a "1" back.
The target reads the "1" and knows the system has worked. (It then returns to do a whole load of irrelevant stuff.

As you can see I have put a debug in each code (only one in each). The "target" is showing that b0 = "1" at it's debug, so it must then be sending a "1" back (I can identify this flash on the LED). The debug from the "display" is reading as " " (space, or 32). The display is obviously receiving some data, otherwise it would timeout and there would be no debug sent. I am just completely foxed as to why is is receiving a " " from the "target". If I change line 10 in the target code to anything but what it is, the debug from the display shows nothing (however it is still debugging, so it must receive something).

I am using up to date Prog Ed on windows XP. This communication was working on the breadboard. I then moved the display to a PCB and it communicated with the breadboard. I then moved the target, and it stopped. I then changed the target and it started working as it is (had to change the code from the original to get it this far though).

Any ideas what is causing the rouge " "? :confused:
Thanks in advance.
David. :)
 

Attachments

westaust55

Moderator
David,

Firstly, are you using 40X or 40X1 chips?
Your serin code includes timeout functions which are not available in the 40X but currently only the 40X1 (and 28X1).
 
Last edited:

westaust55

Moderator
In your target code, you are using the SETINT command and an interrupt routine to wait for incoming data.

When you detect the input 7 pin has data you jump to the interrupt routine and use the serin command.

I would suggest that by the time the serin command is actioned, the "1" has partially passed and therefore not seen correctly.
A possibility may be to use the PULSOUT command to send a pulse through output 7 of the "Display" PICAXE then go into the serout command.

May also be worth considering adding a qualifier or marker string before the data "1" so the two PICAXE chips are synchonised.
 

alband

Senior Member
I am using a pulsout in the display code, and the "1" seems to be getting to the target. The "target" is then sending information back (without interrupt usage) but the display get the ASCII character "space" or " " (i.e. 32), not the "1" it should be receiving.

BTW I don't blame you for missing the pulsout, I always find it incredibly hard trying to understand other peoples code, so thanks.
 

westaust55

Moderator
Okay, yes spied the pulsout command. :eek:

Have to dash for work but find your code structure seemingly confused.

You have goto's to label TS_miss:
but there is not "GOTO ....." at the end of that piece of code so it can flow into the next part with the label trgt_chck:

There are GOSUB's to the label trgt_chck: so a return is required. There is a RETURN amongst the code.

But if the target check fails you flow through into the label Com_error: and at the end of that code you have GOTO Welcome

So as I see it, you can leave return addresses from GOSUB commands on the stack and confuse the program interpreter.

Sorry will be some time before I can get back to look further at the initial problem.
 

westaust55

Moderator
Had another look at your code.

In the Display code, you have:
Code:
trgt_chck:	serout 0,T2400,(254,128,"Target R",254,192,"eply?...")
		serout 0,T2400,(254,128,"Target R",254,192,"eply?...")
		pulsout 1,100
		pause 1000
		serout 1,N2400,("1")
		serin [2000,Welcome], 7,N2400,b1
		debug
		if b1 = [COLOR="red"]"1"[/COLOR] then
so, as you discuss, you are looking for b1 = "1" (which is the same as b1 = $31)



BUT, in the target code you have:
Code:
; Target emplier
		setint %10000000,%10000000
label_0:	let b1 = 0
		let b2 = 0
		if b0 = "0" then label_0
		if b0 = [B][COLOR="Red"]"1" [/COLOR][/B]then label_2
		if b0 = "2" then label_3
		goto label_0
		
label_2:	let b0 = 0
		serout 1,N2400,([COLOR="red"][B]"2"[/B][/COLOR])
		goto label_0
So if the target received a "1", you are sending back a "2"

As such, the display code will never receive a message indicating that the target is receiving.
 

alband

Senior Member
Right, that is another problem.
I've had it on "2" because that seems to be th only number I can use where the display will recieve anything. If I change it back to "1" then the display recieves no data, but still seems to perform the serin command.
Currently though (with the "2" in the taget code), the display is recieving " " or $32.
 

westaust55

Moderator
It is a bit hard to try and help when the code you provide is not that which is giving you problems. Results in others spending time following "red herring".

"2" does equal $32 = decimal 50

but for a space, " " = $20 or decimal 32,

so which is it? :confused:
 

alband

Senior Member
Sorry, I got confused, I thought $ meant decimal.

The target sends "2" and the display is receiving decimal 32 i.e. " ".
 

westaust55

Moderator
Serial comms confusion (and program errors)

I have tried you code in the PE simulator as far as the area you are having problems with and it seems to be working so at a loss there.

= = = = = = = = =

However, run into a simulation problem as we can only select the 28X to represent the 40X and this gives simulation problems.


In the "Display" code

The first line is: let dirsc = %11111111
The makes all pins of port C as outputs. The default is inputs for the 28X/X1 ---- AND YES recognise you have a 40X and that uses port D as the inputs

In your subroutine prc_clear you have the line:
let pinsc = %00000001
so portC pin/bit 0 is turned on and all other bits/pins are turned off.

Then back near the top of your program you have the lines:
Code:
Start:	gosub prc_clear
		serout 0,T2400,(254,128,"Select M",254,192,"ode...  ")
		
		if pin2 = 1 then left	'Decision command
		if pin3 = 1 then right	'Decision command
		if pin1 = 1 then mode	'Decision command
BUT . . . . with the 28X/X1, pin1, pin2 and pin3 are inputs on portC so nothing is read. so the code goes around in a loop - not possible to simulate fully. :(


EDIT: time for Rev Ed to expand the PE and enable selection of 40 pin devices in their own right to permit full simulation
 
Last edited:

alband

Senior Member
Finally, got it sorted!
Sooo, much relief here! :D:)

It needed a grounding resistor between the serial and GND (obviously). The odd thing is, is that I've been running it for a while and it was working fie without one... Oh well.

Cheers (especially on the "gosub" stuff).
 

alband

Senior Member
As said in another thread, I have swapped both chips now for some brand new ones, with IC holders. This was because a few of the I/O had been fried by the soldering iron :eek:
The problem is, is that the target has stopped working.
I had the target communicating using the old chip (the old chip could communicate but some of the other ports which I needed had been fried) with the display using a new chip. Once I de/resoldered the new chip and IC holder on the target, it stopped working.

Symptoms:

The program is obviously correct because it worked before.

As said, the communication from the Display to Target uses and interrupt, triggered by a pulsout. I put a debug right after the "interrupt:" label and it never reaches it, showing that the target isn't receiving the pulse needed to interrupt it. (the code is almost exactly the same as the stuff posted before, just with a few amendments to sort out the sub routine problem spotted be West)

To test it further, I put an LED across the serial line and GND line whilst it was all connected, and I got no flashes. However, if I connected the LED in the exact same way, but disconnect the serial line and GND line from the target, I get the expected pulsout flash, then serout flash.

Since there is no flash when the serial line is connected to that target, but there is when it is disconnected, I assumed that the serial line on the target must be shorting with GND. It was not.
Furthermore, if I put a wire from the +5V on the target, to the serin pin (i.e. simulate the pulse to interrupt it), the target interrupts correctly.

One other bit of information that might be useful: If I put the old target chip back in the target and connect everything, I do get the serial flashes from the LED, but the chip still doesn't seem to receive anything.

Any further ideas on this long winded, brute of a problem.

Cheers :)

Edit: the exact resistance from the serial line on the target to the GND is 94k. Don't know if this signifies anything.
 
Last edited:

alband

Senior Member
Old two chips: soldered straight into PCB - not a good idea. Some of the ports on each broke, but the ones required for communicating were undamaged.
New chips: Put into IC sockets after I had soldered into PCB.

New Display chip worked with old target chip. Replaced the old target chip with new one and it stopped working.
 

hippy

Ex-Staff (retired)
It could be that the accident which led to the original failure of the chips has had some other affect which is causing further failures.

It may be an idea to re-build the circuit on breadboard and get the chips working there ( at least with enough circuit to prove the communications and operaton etc ). Then perhaps rebuild new circuit boards from the ground up, testing as you go.

I doubt that's what you wanted to hear but it will quickly become an expensive and frustrating business if plugging new chips into a dodgy circuit keeps killing them off.
 

alband

Senior Member
I've put the target circuit back on the breadboard. (easy since the only external components are the download circuit, 4k7 pull-up, and a diode.

As before I have an LED across the serial line. As soon as I plug in the PICAXE, there are no flashes, if I take it away, the LED flashes as expected.

Also, the target is behaving as it should, when I put the serin pin high (simulating a pulsin as mentioned before).

So, something about having the PICAXE connected, is lowering the logic level of the pulse and serial.

I also have a 5k6 across the serial line to tie it low. That is soldered so I put a 15k on the breadboard to make it a near 10k.
 

alband

Senior Member
It took a days worth of sitting feeling rubbish and accomplishing nothing, then one divine moment of inspiration, but I solved it.

I had previously had a different diode set-up so when I saw a solder bridge I didn't take any notice as it had previously been necessary. I eventually noticed my past/present diode combination, on the breadboard, since I had copied the PCB.

Sorry it was such a waste of your time :eek:

Thanks for your efforts though, much appreciated as always.:)
 
Top