How to use unsigned char arrays with external SRAM?

Hi guys, I am using a sketch created by someone else and would like to store some variables in an external SPI RAM IC to reduce to AVRs internal RAM usage. The following is a segment of code taken from the sketch:

static unsigned char program[kRamSize];
...
program_start = program;
program_end = program_start;
sp = program+sizeof(program);

I am trying to move the char array called program to an external SRAM IC. All calls to the program array will be sent to a function which writes the bytes to (or reads bytes from) the SRAM IC. To get the size of the program variable from the SRAM IC, I would simply use a for loop to increase a count (such as an int) for every byte greater than zero read from the SRAM IC like so:

for (int i; for i < 100; i++)
{
    val = sram_read();
    if (val > 0)
    {
      count++;
    }
}

However, I am confused as to how to handle the following code when using the external SRAM IC:

program_start = program;

Each time something equals the program variable (which will be stored in the SRAM IC), I need a method to read each byte from the SRAM IC to be used in the code (such as the above line) without exceeding the AVRs SRAM (as the array could be a lot larger than the AVRs SRAM); I am unable to read all of the data from the SRAM IC as the AVRS internal SRAM will be exceeded and I cannot read only a few bytes at a time (such as 1KB) as I do not know how the rest of the sketch operates (I need to deal with the array which will be stored in the SRAM IC just like it is handled above, as if the variable was stored in the AVRs internal SRAM). In the above code line, I am assuming each byte within array program_start is now equal to each byte within the program array (so if program[0] = 5 then program_start[0] also = 5) but I do not understand how to make this work externally via an SRAM IC.

So my question is, how do I make all equals calls to the array program work when the array is in an external SRAM IC?

Thanks in advance for any help or guidance with this matter,
Dan.

for (int i; for i < 100; i++)

Does that even compile?

sorry, ignore the for inside the brackets. The typo is because I didn't copy it, I just wrote in the code box is as an example to show how I would find the size of the array.

I'm puzzled by what it is you're trying to achieve, but either straight C and explicit accesses, or a C++ class and some operator overloads would seem to me to be useful starting points for reading.

The code segment is actually taken from TinyBASIC Plus and I am trying to extend the program memory by using an external SRAM IC. From having a look at the code, the char array called program seems to be where the BASIC program (written in TinyBASIC Plus) is stored so I am planning on replacing all calls to this variable with calls to the external SRAM IC. I am stuck at the point where another variable (program_start) is equal to the program array (as shown in the first post) as I am not sure how to make an array stored in the SRAM IC equal a variable stored in the AVRs internal SRAM without copying the contents of the SRAM IC to a variable in the AVRs internal SRAM (I cannot do this as the array stored in the SRAM IC could be larger than the internal SRAM).

I am trying to extend the program memory

Sorry, not possible on basic AVRs. On the other hand, if you're trying to provide an extension to data storage, that's doable indirectly, though you need to consider where the data comes from after power up. Maybe SD?

I'm not trying to extend the program memory (ROM) of the AVR but the program memory available to TinyBASIC (which is RAM).

Can we cut out the hand-waving, and just post the code?

I don't see what your problem is, apart from where the data in the external RAM originally comes from, and why it can't simply remain there.

Here it is on github: https://github.com/BleuLlama/TinyBasicPlus/blob/master/Arduino/TinyBasicPlus.ino

The array probably can stay in the external SRAM IC but I am not sure how to access it in the same way TinyBASIC does when using an external SRAM IC. I am not sure how things such as the equals code in the first post would work if the data is external (I can't bring the data into the AVR as it would be too large) . I need a method to use external SPI SRAM as if it was internal RAM, meaning things such as equals (the code in the first post) would work for the external RAM.

Did you read reply #3?

Yes I did, but I'm not very experienced in C so need some guidance on this if possible.

but I'm not very experienced in C

So get experienced in C++. If you want someone to do this for you, post in "gigs and collaborations"

Any good tutorials which are more embedded hardware related (programming AVRs etc)? I only seem to be stuck at the equals instructions regarding variables (with external SRAM) through the TinyBASIC sketch. I just need a method to make an internal array equal the external SRAM array without bringing the data in (at least not in one chunk due to the larger size of the external SRAM; it could be bought into the AVR in small chunks only if TinyBASIC would still work by using this method which I am not sure about) the external SRAM into the AVRs internal SRAM (by this I mean the data in the external SRAM must be able to be used in the TinyBASIC sketch just like it is with internal SRAM; the code line with the equals operator in the first post is an example of how I need to be able to access and use the external SRAM variables).

Jeez I’m confused and I know nothing about TinyBasic, but if you have two arrays of data, one in the AVR RAM and the other in external RAM write a loop that scans the AVR array and compares it with the external array, one byte at a time, similar to what you did in the first post.

You cannot use the = operator (well you could if you overload it but that’s out of your league I think).

only if TinyBASIC would still work by using this method which I am not sure about)

What does TB have to do with this? Is this a C question or a TB question? Does the code have to be written in TB?

need a method to make an internal array equal the external SRAM array without bringing the data in

Now I’m even more confused, do you want to move the AVR data to the external RAM (or VV)?


Rob