serial coms problem

grandtippler

New Member
Hi All,
I'm trying to use a 28a to communicate with a GPS with a serial port.
The problem is that only every 2nd or 3rd character from the GPS is displayed on my LCD. The characters that get through are ok so I know I've got the baud rates ok.

Does anyone have any idea why I'm only getting every 2nd or 3rd char?

Here is the bit of the code which takes the serial data 8 chars at a time and dumps it to the display:::

Main:
for b0 = 50 to 58 ‘ start a loop
serin 1,N2400,b1
write b0,b1 ‘ write value into b1
next b0

for b0 = 50 to 58 ‘ start a loop
read b0,b1 ‘ write value into b1
byte = b1
GOSUB SendDataByte
next b0
goto Main


Thanks,
Brian Mc
 

MartinM57

Moderator
A couple of (or 4!) observations:

1. You have no control of when the GPS unit sends you data, so you have to prioritise being ready for it (ie being at the SERIN command as much as possible). If you're not at the SERIN command when the GPS starts to send, you are likely to lose that character
- this means you have to minimise your time elsewhere.
- tricks for this are
....overclocking the PICAXE with a 16MHz resonator - I have a real-time application that has gone from only just working at 4Mhz to absolutely flying at 16MHz. Note that you will have to change the baud rate in the code to 600 to ensure that you communicate at 2400 due to the increased speed
....time-efficient code (see below)

2. I can't see why you use WRITE/READ statements - these use the non-volatile memory of the PICAXE which
a)I don't think you need to do and you might actually wear it out!
b)*might* take longer to execute than a POKE/PEEK pair that start using the (volatile) RAM memory at $C0

3. When I was struggling with my app at 4MHz I 'unwrapped' the loops into straight line code. This made quite a difference. So in your example, replace the first loop with:
serin 1,N2400,b1
poke $C0, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C1, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C2, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C3, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C4, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C5, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C6, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C7, b1 ‘ write value into memory
serin 1,N2400,b1
poke $C8, b1 ‘ write value into memory
...at the expense of using more code memory

4. I can't see the code in
SendDataByte, but again it needs to be as efficient as possible
 

hax

New Member
Or if you know what you are looking for you can use the qualifier to send just the data that you need. Use b0 to blank out the data you dont need.:




GetLatitude:
' use b0 to skip over decimal point
serin,N4800,("$GPGGA,"),b0,b0,b0,b0,b0,b0,b0,b2,b3,b4,b5,b0,b6,b7,b8,b9
b1 = "0"
'sertxd("Lat: ", b1,b2,b3, "deg", b4,b5, ".", b6,b7,b8,b9, "min", 13,10)
return

GetLongitude:
' use b0 to skip over decimal point
serin,N4800,("$GPGGA,"),b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b1,b2,b3,b4,b5,b0,b6,b7,b8,b9
'sertxd("Lon: ", b1,b2,b3, "deg", b4,b5, ".", b6,b7,b8,b9, "min", 13,10)
return



 

Simmicht

Senior Member
The default is 4800 on most models. there is a configuration sentence that can be sent to re-define parameters. PGRMC sentence works for GARMIN (maybe)

 
 

andysc

New Member
I've searched the forums, but there doesn't seem to be a definitive answer to this:

In the BASIC manual (picaxe_manual2.pdf), under serin, there's a code example:

for b0 = 0 to 63 ‘ start a loop
serin 6,N2400,b1 ‘ receive serial value
write b0,b1 ‘ write value into b1
next b0 ‘ next loop

I can't get this to work reliably: it seems that a 4MHz (or even at 8MHz) picaxe 18A can't get round the loop fast enough to read the data.

MartinM57 asked why tipple used write rather than the faster poke... well, probably because that's the example in the manual.

But I can't get it to work at all reliably with poke, either, and I'm only trying to read half a dozen bytes, so it's not like I'm asking it to stay on track for very long.

So, should I expect that code sample to work at 2400 baud on a 4 or 8 mhz picaxe, or is it really a bit misleading?

Andy
 
Top