Serin crashes 28X1 picaxe

frank_p

Member
Hi all,

I just finished an RS485 network and am testing a node individually directly from com port with the following statement:

serin 1,N2400_4,addrByte,serialByte

All I receive is 2 bytes, address byte and command byte (simple protocol).

The problem is i might also receive address bytes which are to be ignored by a particular picaxe. If the address byte is not the same value as the fixed address on the board it is ignored.

When I send about 20 2byte messages the picaxe crashes and needs to be reset.

Can anyone give me a clue why this happens.

Thanks for your estimeed help (as usual).

Frank
 
I suspect it's not the PICAXE "crashing" but your program waiting for input during which time it cannot accept a download.

Also, SERIN has to be ready and executing to receive the data sent so if it's not you can get out of sync, the last byte of a two-byte packet being seen as the address, and SERIN not continuing until it receives another byte.

Often the easiest way to tell what's going on is to wrap the SERIN code ( where it's likely to be waiting IMO ) with something which reports when it's about to execute and has finished ...

SerOut pin, N2400_4, ( "[" )
SerIn 1, N2400_4, addrByte, serialByte
SerOut pin, N2400_4, ( "]" )

Or set then clear a LED on an Output Pin, or issue two SOUND commands.
 
Last edited:
@hippy

From the computer I send 5 consecutive commands addressed 1 to 5, so each MCU will only have 1 command which it should execute.

So if i understand correctly i might be losing one byte somewhere after a couple of commands are set?

The software of the computer is always sending 2 bytes not one, and this i'm sure about.
 
That's what I'd suspect. The commonest problem is probably sending byte-pairs too soon after each other. Noise on the line could also fool the SERIN to thinking a byte has been sent when it hasn't.

There are various things which can be done to improve the situation, addresses which have more complicated bit patterns than 1 to 5 ( eg $33, $5A, $C6 etc ), serial qualifiers, packet checksums and an acknowledgement to sender when a node has handled a message and is about ready to receive another packet.
 
The simplest thingto do is to change the addressbyte into a qualifier on each chip and send a 'wakeup' header e.g. $55, $5A

so computer sends

$55, $5A, address, data

picaxe 1 is
serin 1,N2400_4,($55,$5A, 1),serialByte

picaxe 2 is
serin 1,N2400_4,($55, $5A, 2),serialByte

etc.

Then the PICAXE will only ever process serialbyte if its address is correct.
 
Last edited:
Back
Top