PDA

View Full Version : Eliminating serstring arrays



Newzed
01-30-2007, 11:00 PM
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, ["Communication OK", 13, "You are clear to send",13,10]
---------------------------------------------------------------------
In the Master I wrote:
--------------------------------------------------------------------
DO
··· SERIN si\fc, baud, [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 (mailto:Module?Newzed@aol.com)
·

Chris Savage
01-30-2007, 11:55 PM
Sid,

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

Newzed
01-31-2007, 12:15 AM
Chris, the piggyback uses a BS2 for the Master and a BS2E for the Slave so I have no EEPROM available.· I have to make do with what is available.· Maybe some day I'll use two BS2pe's, then I can go the EEPROM route.

I appreciate your comments.

Sid

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?

Newzed@aol.com (mailto:Module?Newzed@aol.com)
·

Chris Savage
01-31-2007, 12:37 AM
Sid,

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

Newzed
01-31-2007, 01:32 AM
Chris, I can probably do with a byte-for-byte exchange instead of the string response from the Slave, and I may change to that.· Initially though, since I was experimenting, I wanted to see what I could do with sending a string to the Master.· Programming space with the Slave won't be a problem since I have eight banks for code.

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 (mailto:Module?Newzed@aol.com)
·

Chris Savage
01-31-2007, 03:31 AM
Sid,

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