Indexed adressing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Indexed adressing

2,770 Views
Truk
Contributor I
I have to read from different tables anywhere in the 16-Bit range and store the data in the SEND-BUFFER (max. 67 Bytes) in the 16-Bit-range of the RAM. The data from the buffer will be sent in a slow speed to an periph.device, only a few Bytes per mainloop. Therefor I cant store the data on stack?
Which is the simplest way to do this?
Has somebody a sample?
regards
Truk
Labels (1)
0 Kudos
Reply
5 Replies

765 Views
bigmac
Specialist III
Hello,
 
If further data needs to be added to the buffer, before all the previous data has been sent, the buffer would need to be of the "circular" type (or FIFO), with a "head" pointer and a "tail" pointer to keep track of the position of data entering and leaving the buffer.
 
I am not sure if this is part of your requirement.
 
A further thought - since your data is already present in flash, I would guess that you don't really need the RAM buffer at all.  You would only need to set up a pointer to the data table in flash, read one byte at a time to be sent to the peripheral, and then increment the pointer.  The first byte of each data table could contain the number of bytes to be sent, or alternatively the presence of a special byte value could indicate when the end of data is reached.
 
I have used this approach when sending "canned" message data to a SPI.  Each message was terminated by a null.  I also provided an additional table containing the start address for each message, so that an individual  message could then be referenced by an index number.
 
Regards,
Mac
 
0 Kudos
Reply

765 Views
Truk
Contributor I
Mac, thank you for your idea too. In my situation it is more complicated, because the data to be sent are from different tables. There are also variables included from the RAM (between code from tables). So it seems better for me, to put all data together before sending. The peripheral is an intelligent LCD (http://www.lcd-module.de/deu/dip/edip.htm) with a very slow SPI-Bus. So the data takes until 15 RTC-Loops to be sent. Therefore I have also a sendpointer and a end of string variable.
(I hope you can understand my bad English)
Regards,
Truk
 
0 Kudos
Reply

765 Views
bigmac
Specialist III
Hello Truk,
 
It all depends on whether you have sufficient RAM available for a 67 byte buffer.  You might find you can considerably reduce the size of the buffer if it has to store the "variable" component of the data only, and not also the "fixed" component.
 
With the indexed message approach, as previously outlined, one of the messages can easily be allocated to the location of a RAM buffer, rather than a data table in flash.  You might also need to maintain a queue of the sequence of messages to be sent, but this is relatively easy to do if each message (or message component) is identified by means of a single byte index value.
 
Regards,
Mac
 
0 Kudos
Reply

765 Views
tonyp
Senior Contributor II
Attached (untested, just typed it in, but looks correct).  At least, you get the idea.  Call the routine by preloading HX with the source address.
 
(Oops! Trying again!)

Message Edited by tonyp on 2006-10-2707:16 PM

0 Kudos
Reply

765 Views
Truk
Contributor I
Many thanks tonyp for help! It works.
regards
Truk
 
0 Kudos
Reply