problem with a noisy serrxd on 20X2

jimruxton

New Member
For some reason I am trouble with serrxd . The values I get are sometimes off by one bit or two ie. I may receive 12 instead of 140. I know the serial in and out line to the chip is ok. If I connect them together I echo values perfectly to my terminal. Here is my code. I'm using a 20X2

main:
disconnect
serrxd b0
reconnect
sertxd (b0)
goto main


The chip programs ok. I'm sending b0 back out the serial port to see if the chip received it correctly. Even when I wasn't sending the data back out the serial pin on the 20X2 the data wasn't being received correctly. I have a decoupling cap at the chip and tried changing all inputs to outputs in case it was some noise acting on the inputs? Any ideas?
Thanks,
Jim
 

Andrew Cowan

Senior Member
It could well be that the oscillator frequency of the 20X2 is slightly off - try using calibfreq to tune it.

First try with 'calibfreq -2' at the top of your code - if this makes it worse, try 'calibfreq 2'. Experiment with the number until it is working reliably.

Andrew
 

tarzan

Senior Member
picaxe_manual2.pdf
Syntax:
DISCONNECT
Function:
Disconnect the PICAXE so that it does not scan for new downloads.
Information:
The PICAXE chips constantly scan the serial download pin to see if a computer is trying to initialise a new program download. However when it is desired to use the download pin for user serial communication (serrxd command), it is necessary to disable this scanning. Note that the serrxd command automatically includes a disconnect command.
 

SAborn

Senior Member
I go with Andrew that the internal clock frequency is slightly off and needs recalibrating, it would appear a common problem with the 20 pin chips.

Do a sertex back to the screen and send a string of "UUUUUUUUU" to the screen and keep adjusting the frequency till you get no corruption in a string of "UUUUUUUUU"
 

hippy

Ex-Staff (retired)
SERRXD will automatically DISCONNECT and there is no reason to RECONNECT in this case, so a better loop to test with will be -

main:
serrxd b0
sertxd (b0)
goto main

When sending characters the SERRXD has to be executing. If you send when it isn't then corrupt data may be received, and with RECONNECT the PICAXE may reset. If multiple characters are sent back-to-back then there will likely be corruption.
 

jimruxton

New Member
Thanks everyone for the suggestions. I got it working most of the time. Strange thing is when I reprogram the chip with exactly the same program a second time sometimes the serrxd still messes up the odd bit. The program I am using as a test is:

calibfreq -5
main:
serrxd b0
sertxd (b0)
goto main

It seemed to be a combination of the reconnect command and the calibfreq. A problem I have in not using reconnect however is that every time I go to reprogram the chip I have to do a reset during the download whereas with the reconnect in there I didn't. Also still not sure why sometimes when I program the chip with exacttly the same program the serrxd still messes up. Maybe I have a bad chip?
 

hippy

Ex-Staff (retired)
The 20X2 uses an internal oscillator which can drift slightly so if the CALIBFREQ hasn't adjusted out whatever the error is then you may still occassionally get some.

Of course it could be some other issue than SERRXD, SERTXD or oscillator frequency. How are you providing the serial input and what are you sending the output to ?
 

jimruxton

New Member
The 20X2 uses an internal oscillator which can drift slightly so if the CALIBFREQ hasn't adjusted out whatever the error is then you may still occassionally get some.

Of course it could be some other issue than SERRXD, SERTXD or oscillator frequency. How are you providing the serial input and what are you sending the output to ?
I'm using a FTDI based adapter http://www.sparkfun.com/products/9115 . I tried both using the typical 22K 10k resistor pair at the input and directly. It doesn't seem to matter. Sending the output to a program on my laptop. I know it is bad on the receiving end because if I use the serrxd data to control the intensity of an LED. It reflects what the data coming back to the computer is. ie the data isn't being scrambled on the return leg of the journey to the computer. Is there a way to still use "reconnect" and not have it corrupt anything? I guess I would need a delay after serrxd. Any idea how long?
Thanks for the help
jim
 

hippy

Ex-Staff (retired)
Are you also using that adapter to download programs to the PICAXE ?

It seems the adapter is compatible with Arduino, in which case I'd expect the signal polarity to be inverse of what the PICAXE expects. That would cause all sorts of problems.
 

jimruxton

New Member
Yes I am also using it to download programs. It was reprogrammed to work for the picaxe. If it downloads programs ok then it should work for serial communications.
 
Top