Eliminating serstring arrays
Newzed
Posts: 2,503
I have been playing around with my Stamp-over-Stamp piggyback.· When I send "A" to the Slave,·I wanted it to send back "Communication established".· This·takes 24 bytes.· To declare a variable
serstring· VAR· byte(24)
used up almost all of my variable space.· So I looked for another alternative - the DO/LOOP routine.· Now when I send an "A" to the Slave, it sends back:
SEROUT so\fc, baud, [noparse][[/noparse]"Communication OK", 13, "You are clear to send",13,10]
In the Master I wrote:
DO
··· SERIN si\fc, baud, [noparse][[/noparse]com]········ ' receive one byte
··· DEBUG com······················· ' display on screen
· LOOP UNTIL com = 10
· DEBUG cr, "Press any key to continue", cr
· DEBUGIN com
· GOTO start
The Master receives and displays:
Communication established
You are clear to send
And all of this takes only a one-byte variable!· I could have sent/received an unlimited number of byte(depending on memory available) until the Slave transmission was terminated with a " 10 ".· The Master looks for a " 10 " in the DO/LOOP, which tells it to terminate the received string.
Try it - it really saves variable space.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
serstring· VAR· byte(24)
used up almost all of my variable space.· So I looked for another alternative - the DO/LOOP routine.· Now when I send an "A" to the Slave, it sends back:
SEROUT so\fc, baud, [noparse][[/noparse]"Communication OK", 13, "You are clear to send",13,10]
In the Master I wrote:
DO
··· SERIN si\fc, baud, [noparse][[/noparse]com]········ ' receive one byte
··· DEBUG com······················· ' display on screen
· LOOP UNTIL com = 10
· DEBUG cr, "Press any key to continue", cr
· DEBUGIN com
· GOTO start
The Master receives and displays:
Communication established
You are clear to send
And all of this takes only a one-byte variable!· I could have sent/received an unlimited number of byte(depending on memory available) until the Slave transmission was terminated with a " 10 ".· The Master looks for a " 10 " in the DO/LOOP, which tells it to terminate the received string.
Try it - it really saves variable space.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Comments
Why deal in entire strings for host/slave communication? In embedded systems it’s almost always betters to use small packets and leave the string representation out of the communication. Instead if you needed to display that the receiving unit could fetch that from EEPROM directly to the display after receiving a 1 or 2 byte (or even 4 byte) packet from the slave unit. This way you wouldn’t need to use all your variable space up on an array. Using a BS2p you could use the Scratch Pad Ram, but I still think ACK/NAK packets should be smaller on embedded systems communication. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I appreciate your comments.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
All your EEPROM space is used up? I bet removing the code that checks the entire string would release a chunk of that. If you send an “A” to the module to check status, I would think it would respond back with a “B” or something similar. Intuitively if you’re sending a single character request you could get a single character response. Likewise if you’re expecting a response of, “Communication Established” then wouldn’t you be sending a command of, “What is the status of communication?” I guess what I am trying to say is if you just need to know the status of the connection you don’t need so much overhead. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
By EEPROM, I assume you are referring to the low end of the memory using WRITE/READ.· If I switch to BS2pe's, I'll have 16k of memory I can write to with the STORE commnd.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Yes, I was referring to the on-board EEPROM. You could READ/WRITE, however internal strings can be stored more easily through the use of DATA statements in the code since chances are they won’t need to change during runtime.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support