@ptr usage

jmumby

Senior Member
I want to fit two nmea strings in the scratchpad of a 28x1. To get the start point of the second string I use @ptr so...

Code:
FIRST_STRING:
SEROUT GPS_TX,GPS_BAUD,("$PSRF103,00,01,00,01*25",CR,LF)
HSERIN [1000,NEXT_STRING],0,126,("$")

NEXT_STRING:
b1 = @ptr
b1 = b1 - 2        'REMOVE CR AND LF
put b1,","           'MAINTAIN CSV FORMAT
b1= b1+1
b2=127-b1

SEROUT GPS_TX,GPS_BAUD,("$PSRF103,05,01,00,01*20",CR,LF)
HSERIN [1000,WRITE_DATA],b1,b2,("$")
So I figured to only read out to the last byte used I would just issue the @ptr command again but this just gives me the initial @ptr result again.

Am I missing the concept or is this a case of sorry dude old firmware.
 
Last edited:

hippy

Ex-Staff (retired)
'ptr' is the pointer, '@ptr' is what the contents of what the pointer points at. You probably need ( untested ) ...

b1 = ptr
b1 = b1 - 2

or

b1 = ptr - 2
 

BCJKiwi

Senior Member
1. you need to know where the data is stored
2. change the pointer to that position
3. read the data from the position

so if the 2nd set of data starts at position 10;
ptr = 10 ' position pointer
b1 = @ptr 'store data at pointer location to b1
b1 = b1 - 2 'manipulate value of b1

The pointer will be left at the last position by default.
 

BrendanP

Senior Member
b1 = b1 - 2 'manipulate value of b1

My understanding was that 2ptr can be used in the indentical way as byte storage so the above could be written.

@ptr=@ptr-2

Is this correct?
 

BCJKiwi

Senior Member
Well yes,
but then the values stored in the scratchpad, not a working variable would be changed. So when the scratchpad is next read from it would now have the new value. If that is what is wanted, then OK.

Each byte of data will be in its own address so if a string of data that is 10 characters long is being stored, then ten sequential addresses would be used.

When time comes to send, then the output procedure can add the ","s in between the data. The ","s and CR, LF don't need to be stored (or read) if not used.

If the idea of the -2 is to remove the last 2 characters (CR, LF), then it won't work as the the -2 would actually change the value of the character at the current pointer address.

The best way (for me) to sort this type of problem, is to write little code snippets and run them in the simulator in step mode. The simulator settings allow you to see the serial output, the scratchpad contents etc etc so you can sort out how all this works for exactly what you wish to achieve.
 

BrendanP

Senior Member
I haven't used the sim as yet but will do so now, Ive got some scratch pad probs to resolve. Thanks Kiwi.
 
Top