28 x1 serial communications help

radcom

Member
I am trying to build an interface for my computer that sets the outputs of a 28X-1 chip to a Byte sent from the computer the byte will vary between 0 and 255 and the out puts should be set accordingly i.e. 0 = 00000000, 1 = 00000001, and 255 = 11111111 but with the code I have all it does is set the pins wrong, the error is in my code for the picaxe and not the rest of the system as I have checked the code with the built in terminal in the programming editor
The code I have wrote is
Code:
 init: let b0 = 0
main:	serrxd [1000, timeout], b0
timeout:	let pins = b0
	debug b0
	
	goto main
I have been working on this for some months now and now I just have no clue I am sure there is a simple solution but since I can't see it any help will be greatly appreciated
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
It comes down to what SERRXD is expecting and what you are sending. As you have it you are expecting a raw 8-bit byte value to be received, using the Terminal you are undoubtedly sending 8-bit ASCII Characters, not the same ...

If you send "255" You are sending three ASCII bytes of value; %00110010, %00110101, %00110101 and your outputs will be set accordingly.

Change to "serrxd [1000, timeout], #b0" and you will be able to do what you want.

Don't forget to send a non-digit after your number or the PICAXE will be thinking there may be more digits to come and won't appear to do anything.
 
Does B0 get set to the correct value by the SERRXD command?
Check that your PC is sending data in the correct format (4800 baud, N,8,1 if you're using a 4 Mhz clock).

If B0 is set to the correct value, does the bit pattern in B0 match the pattern you want to send?
Check that the PC is calculating the correct byte to send to the Picaxe.

Since these are the first two things that came to my mind I'm sure that you've already tried them. Can you tell us what else you've tried and what the results are?

Chuck
 

radcom

Member
I have changed serrxd to serrxd [1000, timeout], #b0 and now it doesn't do anything even if i send a non-digit such as "a" and it doesn't do anything
 
Last edited by a moderator:

moxhamj

New Member
PC comms not working or picaxe not outputting the correct data?

Try just a simple
b0=%01010101
let pins = b0
end

Just to test the pins actually do change as expected.

Probably that will work fine. So it is the PC comms that is the problem. Have a look at this http://www.instructables.com/id/Control-real-world-devices-with-your-PC/

There are a few tricks and tips in there. For PC to picaxe to work, *everything* has to work. It might help to copy that instructable, however simple it may seem, and then you can change one thing at a time and evolve it into what you want.
 

therowes

Member
I had no end of trouble with serial comms when using a debug statement in a recieve loop ( bytes getting truncated and shifted into other bytes). Are you using an external resonator ? I've 1 chip that won't do serial work unless its on an external resonator ( it works ok for everything else ? ). If your'e using the program editor terminal to "send" the data you maybe sending upto 3 bytes ( in ASCII ) for each number typed ?
 

radcom

Member
I have read that instrustable it is what actully give me the idea for this interface regarding the link the problem is with the picaxe reciving the value entering it in the variable (b0) I know there is no problem with the picaxe setting the outputs to the variable as i have a test program that works fine

The test program is
Code:
init:		let b0= 0
main:		pause 200
		let pins =b0	
		let b0=b0+ 1
		debug b0
		goto main
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
How do you mean "one of the problems" ?

Can you be precisely clear in exactly what you are sending and how. With our crystal balls taken away and sold-off to fund international bailouts it's difficult to second guess what you are doing when we cannot see over your shoulder.

When you send data; what do you send and what is the result, what is stored in b0, how are the outputs affected ?

You can go back to the original b0 without a # and then just send one character, say "0"; do outputs 5 and 6 go high, the rest stay low ? If you send "1" does output 0 also go high ?

With the # you may need to send digits individually. To set all outputs high try "2" send, "5" send, "5" send, "X" send - what does that do ?

Also you have a timeout; why ? What happens if your code timesout as you are sending the data ? Try it without a timeout, does that work ?

You could also try with HyperTerm ( can be a pain to setup ) or the AiChip Terminal Emulator ( Finsihed Projects - Communications ).

Footnote : I don't know why people keep adding timeouts to SERIN/SERRXD. In most cases they simply confuse things and actually increase the chance of code failure than fixing problems. With wireless comms, yes, they are useful, for everything else they usually are not. Somehow it seems the idea of having a timeout has been taken as a Good Thing (TM) and should always be used.
 

radcom

Member
"one of the problems" just ignore that as I thought there was another problem which I have check into and is not a problem

regarding what you said about results here are some
if I send 0 with out the # outputs 4&5 go high debug says b0 = 48 $30 %00110000 '0'

if I send 1 again with out the # outputs 0,4,5 all go high and debug says b0 = 49 $31 %00110001 '1'
I count the outputs as ouput,0, output 1, output 2..

I need the time out to see what the debug says before going back to the serrxd but i get the same result with out it so I am sure the problem is not with the time out
 
Last edited by a moderator:
The values that you are seeing in B0 are the ASCII values of the characters "0" and "1".
This is what I would expect to see if you are sending data from a keyboard to the Picaxe through a terminal program.

You need to send binary data or modify your Picaxe program to convert from ASCII to binary.
 

hippy

Ex-Staff (retired)
Your results confirm that your original code was working as it would be expected to.

Adding the # should resolve what you are trying to do; "255" being received as a single number into b0 rather than three separate values sent one after each other. I don't know why that isn't working.

I've also realised I hadn't explained why timeout in cases like this is a bad idea, and while that probably isn't the problem in this case ...

When a timeout occurs it takes some time for the PICAXE to go back to the command which timedout to be ready to receive data. In a simple case where one wants data, the SERIN/SERRXD would simply wait until data is received.

With a 1 second timeout there will be a ~300uS period where it will not be able to receive data. With some 3,000 such 300uS periods per second this gives around a 1 in 3,000 chance that when you send your data the PICAXE will be handling its timeout and miss or corrupt what is sent.

While the odds of missing data seems small, sod's law says that's not the case in practice, and at some point data will be lost or corrupted if you send enough of it. You may get lucky and see no corruption ever or you may get very unlucky and never get any valid data through at all. Usually you will see intermittent corruption and often not understand why that is or what is causing it when it's entirly down to the software design chosen by yourself.

The numbers and odds may not be exact and depend on system speed and size of timeout but the principle remains. Unless you need to take specific action in the absence of data being received in a certain timeframe, don't use a timeout. It will simply increase the risk of data loss and corruption - A worse situation than not having a timeout.

Added : Real world analogy -- You're waiting for someone to come and fix something, at some point you get fed up waiting and storm off to phone head office to find where they've got. You're assured they're on their way, return to waiting only to find a note on the floor saying they'd turned up while you were on the phone, you never heard them, and they've gone away.
 
Last edited:

radcom

Member
I do intend to remove the time out after I get the program fully working could you show me the code with the # as I must be entering it wrong
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
You could try this, it's where I would start ...

Code:
Do
  SerTxd( "Ready ...",CR,LF )
  SerRxd #b0
  SerTxd( "Received value ",#b0,CR,LF )
Loop
 

radcom

Member
tryed it and it doesn't work in the simulator and also doesn't work on the chip
 
Last edited by a moderator:

westaust55

Moderator
How do you mean "one of the problems" ?

Can you be precisely clear in exactly what you are sending and how. With our crystal balls taken away and sold-off to fund international bailouts it's difficult to second guess what you are doing when we cannot see over your shoulder.
@hippy,
I have found a cheap new one for you:
http://cgi.ebay.com.au/120MM-Brazil-purely-natural-crystal-ball_W0QQitemZ170267528517QQihZ007QQcategoryZ3226QQssPageNameZWDVWQQrdZ1QQcmdZViewItem
:D
 

radcom

Member
I think have just got it it working finaly I now just need to tweek the computer side to make it send a none digit as hippy said I do intend to do a instrutable at some point.

Now I have another problem the software I wrote with it seems to be sending the data out as seprate numbers i.e. if it sends 255 the sends 2 5 5 not 255 its suposed to work like the program hippy wrote only the data to send comes from the command line not entered directly to the form I can post the source code for my program if neccesary

the program is supposed to get the data from the command line then send the data to the picaxe then the program is supposed to end I have visual basic 6.0 and 2005 express edition but I would perfer to keep the program in vb 6
 
Last edited by a moderator:
Top