Ram or Scratchpad?

steliosm

Senior Member
Hello all.
I have been trying to identify pros and cons of using the one instead of the other. Besides the available space to use, are there other details one should take under consideration when choosing one over the other?
 

lbenson

Senior Member
The particular advantages of the scratchpad, other than size, are its ability to be the target of serial background receive, and in X2 slave mode for its first 128 bytes to be seen by other devices (picaxes) as i2c eeprom.

Otherwise, to my mind, it's "take your pick". Use ptr or bptr for indirect addressing, PUT/GET or POKE/PEEK for direct. bptr has the advantage of being able to access the named variables (but also to overwrite them unintentionally).
 

hippy

Technical Support
Staff member
Available scratchpad always starts from location 0, whereas RAM starts from wherever your variables end, or 56 on an X2, 28 on an M2, to play safe.

Otherwise it's really your choice. If you could use either it doesn't much matter which you use.
 

Aries

New Member
... scratchpad ... in X2 slave mode for its first 128 bytes to be seen by other devices (picaxes) as i2c eeprom.
My reading of the manual - and I hope I'm right, as I am about to use 255 of them - is that the first 256 bytes are available in the X2s (apart from the 20X2 which has only 128 bytes anyway).
 

inglewoodpete

Senior Member
If you're using the hSerial port for background serial reception and you want to share the scratchpad storage with other data, you can easily restrict the size of the received data buffer in the scratchpad. This allows you to use the remainder of the scratchpad for other storage functions.

In your initialisation, along with hSerSetup, enable Serial interrupts via the SetIntFlags command. Then create your interrupt service routine around the following template:
Rich (BB code):
Interrupt:If hSerInFlag = 1 then
             hSerInPtr = hSerInPtr And %00111111  'Restrict pointer to 0-63 (Must be first command)
             hSerInFlag = False
          EndIf
          <insert other interrupt code here if required>
          SetIntFlags <flag>, <mask>              'Restore interrupts
          Return
With judicious use of the Boolean (And/Or) masks, it should be possible to move the serial buffer away from the bottom of the scratchpad, if required.
 
Top