28X2 Program size?

rmtucker

Member
My program is currently taking approx 1070 bytes.
Having read the following from the manual,Does this mean i am about to run into problems?
Or can the program take up to 4096 bytes without any problems?
Or will i have to split my program and load it into seperate slots and call the slot# when required?

However program slots can be combined into one ‘long program’ as long as the
following points are noted:
1) No gosubs (including the interrupt) can be shared between program slots
2) The gosub/return stack is reset when moving from one slot to another
3) Outputs and variables/scratchpad are not reset
4) The ‘run X’ command should be regarded as ‘goto to the start of program X’
 

hippy

Ex-Staff (retired)
The program can be up to 4096 bytes long, so you're only using 25%.

Each of the four slots of a 28X2 and 40X2 can hold a program of 4096 bytes each. You shouldn't have to contemplate splitting your program across slots at the present time.
 

rmtucker

Member
Thank You.
It was just the following statement from the manual that confused me.

However program slots can be combined into one ‘long program’ as long as the
following points are noted:
1) No gosubs (including the interrupt) can be shared between program slots
 

hippy

Ex-Staff (retired)
On the GOSUB issue, what that means is you can't have ...

--------------------------------------------------------

#Slot 0
Run 1

MySub:
SerTxd( "In my sub" )
Return

--------------------------------------------------------

#Slot 1
Gosub MySub
End

--------------------------------------------------------

The "MySub" subroutine has to be included with Slot 1 where the GOSUB which references it appears.
 

VK4CP

New Member
My project has reached the limit of 4096 bytes, and I have been (reluctantly) scaling back features, and trying to make my routines more efficient to save a few bytes here and there, where I can.

PICAXE manual said:
program slots can be combined into one ‘long program’...
I find this confusing as well.
If program slots can be combined into one, then there would be 16k worth to play with, not just 4k.

So, if you really can combine, what is the trick to this? :confused:
I don't have any slot directives in my code yet, but would like to avoid having to break it up into multiple files to program multiple slots.

I could do with another 2k worth of program space (ie; around 6k in total) to do everything I would like to.

If I do have to employ multiple slots, would I be better off having separate .bas files for each one, with the appropriate #slot directive in the first line?
I can see this becoming potentially messy.

Ideally, you could have the programming editor open, with the separate .bas files for each slot, and link them, so they all act as the one big file within the programming editor, handy for syntax checking between all slot files.
* Not sure if the Programming Editor development crew read this forum, but that would be a handy feature on my wish list!

Also, Manual 2 (V7.7 05/2011) mentions that EEPROM data area is shared between slots.
Fair enough, that's clear.

What about the Flash memory area?
Is that shared too?

I also make extensive use of the scratchpad area.
Can I assume that is shared between all slots?

Cheers,
Adam
 

Technical

Technical Support
Staff member
Think of your long program cut in half in the middle. You can jump from each half to the start of the other half, but cannot share subs between each half.
Each half is 4096 bytes, and is a separate .bas file
When you get to the end of the first half you use 'run' (instead of 'goto') to move to the second half.

RAM and scratchpad and eeprom are all shared between each half.



so program in slot 0

Code:
label0:
{code}
run 1  ; equivalent of 'goto label1'
and the program in slot 1

Code:
label1:
{code}
run 0 ; equivalent of 'goto label0'
 
Last edited:

inglewoodpete

Senior Member
You can't chain the 4k slots together into one big contiguous program area.

I asked a similar question back in May and this thread should help you get on your feet. Once I'd got the code sorted out, I included a code sample to explain how I did the slot swapping. Also, I used just one source-code file but used defined code blocks for conditional "compiling" of the code for the 2 slots. Common subroutines are compiled, where required, in both slots.

My applications were complicated by having timer and comms interrupts, which needed to be initiated and handled in both slots, since timer and interrupt control is lost when swapping slots.

Edit. I just remembered: the subroutine "stack" of return addresses is lost when you change slots, so you always enter the "top" of the program page when starting execution in a new page. Even if you exited that slot from a "run" statement in a subroutine.

In a nutshell, you need to use good, modular, progrogramming techniques to make it work efficiently. I hope this helps.
 
Last edited:

Steve497

New Member
28X2 data storage limits. 3K SPI write.

Regarding: "Think of your long program cut in half in the middle. You can jump from each half to the start of the other half, but cannot share subs between each half.
Each half is 4096 bytes, and is a separate .bas file
When you get to the end of the first half you use 'run' (instead of 'goto') to move to the second half.
RAM and scratchpad and eeprom are all shared between each half."

I am designing a system with a 28X2. I have an external SPI EEPROM with 3K stored on it. The other device in my system requires that I write the entire 3K block using SPI to one register (one memory location) and it will automatically increment its internal address to store the data in itself 0000 to 3000. The problem is, if I deselect its chip select to go get more data from the EEPROM, when I come back it will start loading at location 0000 and overwrite the first data. The EEPROM and other device share the same SPI lines. I was hoping to read the EEPROM data into the 28X2 at one time, then select the other SPI device to dump it all in one pass. I fear the 28X2 does not have memory on board to accomplish this. I don't think the program memory in each slot is accessible for me to dump 3K even if I spread it across slots. This quote from above "RAM and scratchpad and eeprom are all shared between each half" reinforces my fear. I cannot remain tethered to a PC with a serial cable to have memory to dump the 3K at one address. Can anyone think of a way to get the EEPROM 3K dumped into my other device all in one continuous SPI write? I see the 28X2 I2C and SPI share lines, and I don't have enough I/O lines on the 28X2 to bit bang parallel address and data if I design for another RAM chip leaving the SPI device enabled. Thanks for any ideas. Or at least confirm my concern that I can't do it. This is my first time here so I hope I followed protocol.
 

hippy

Ex-Staff (retired)
None of the PICAXE have enough RAM to allow 3K bytes to be loaded and/or written out in one go, and the extra slots won't help with that. This is a 'lack of RAM' issue rather than a 'lack of program memory' issue.

You could put the two SPI devices on separate buses, read from one and write on the other. As each chip select won't be cleared until the transfer is complete; neither should reset as they will just think you are being slow in reading or writing which is allowed.

You can split a single SPI bus to two separate buses with logic gates which would reduce the number of PICAXE I/O lines required.

Do you have a link to the datasheet of the device you are writing to as that might provide some ideas on alternative approaches.
 

Steve497

New Member
I've never seen SPI split, but I guess I can imagine it with a tristate buffer. The separate chips-selects create that function already in each device. Adding additional hardware really blows the board real-estate budget, but it might be the only way. This is too bad since I really liked the simplicity of four wire SPI and its shared bus. While testing it with a Pico scope I also noticed that m16 internal seemed far superior to em64 with a 16MHz resonator. That was unexpected. The same results when using pulsout to see which gave shorter times. Thank you very much for letting me know to stop trying to imagine elaborate schemes to make the 28X2 hold that much data. Now I have to imagine hardware solutions. Do-able, but messy. Thank you for the reply.
 

westaust55

Moderator
I am designing a system with a 28X2. I have an external SPI EEPROM with 3K stored on it. The other device in my system requires that I write the entire 3K block using SPI to one register (one memory location) and it will automatically increment its internal address to store the data in itself 0000 to 3000. The problem is, if I deselect its chip select to go get more data from the EEPROM, when I come back it will start loading at location 0000 and overwrite the first data.
It reads/seems as if you are not sending the starting address location to the external EEPROM or it is not being rec ognised.

In the absence of knowing which external SPI EEPROM you are using, from the 25LC256 datasheet:
The device is selected by pulling CS low. The 8-bit READ instruction is transmitted to the 25XX256
followed by the 16-bit address, with the first MSB of the address being a “don’t care” bit. After the correct READ instruction
and address are sent, the data stored in the memory at the selected address is shifted out on the SO pin.
If you provide a link to the datasheet for the actual SPI EEPROM and "receiving chip" that you are using and post at least a code snippet showing the BASIC program lines you are using to read, disable and then resume reading/writing folks here may be better placed to assist you.
 
Top