Fast External Memory


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,159


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by prstein View Post
    ...

    Robert,

    Thanks for the input, but that device looks way too slow.

    Best Regards,
    Paul

    You can use page writes with the AT24C1024, could that help?

    Features
    • ...
    • 256-byte Page Write Mode (Partial Page Writes Allowed)
    • ...
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    If eight pins is too much you could use a 4 bit interface.
    Still much faster than any I2C or serial EEPROM, particularly when you
    have to wait 10ms after a write cycle.

    If you read a value and then update that value, you are supposed to wait 10ms right there.

    No reason why the pic acting as a RAM chip couldn't perform other tasks until
    it is interrupted,
    as long as there's enough RAM left in both chips to run the program as well.

    I'm sure I've asked about external RAM on this board before (or on the old picbasic list).
    It would be nice to have a fast pic compatible RAM chip, as well as an FPU
    (another thing I've asked about).
    I'm sad that the pic32 chips don't even have an FPU (something I expected).
    Last edited by Art; - 2nd March 2010 at 23:50.

  3. #3
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    Not to keep beating the same drum ...

    I suggest you look at something like the 23A640. You can do sequential reads and sequential writes. And all this over SPI. At 10MHz (and four lines - max), a 32-bit transfer is 3.2uS (that should be pretty fast).

    From datasheet:
    If operating in Sequential mode, the data stored in the memory at the next address can be read sequentially by continuing to provide clock pulses. The internal Address Pointer is automatically incremented to the next higher address after each byte of data is shifted out. When the highest address is reached (1FFFh), the address counter rolls over to address 0000h, allowing the read cycle to be continued indefinitely.
    If operating in Sequential mode, after the initial data byte is shifted in, additional bytes can be clocked into the device. The internal Address Pointer is automatically incremented. When the Address Pointer reaches the highest address (1FFFh), the address counter rolls over to (0000h). This allows the operation to continue indefinitely, however, previous data will be overwritten.
    This, or something similar, should fit your needs.

  4. #4
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Art View Post
    If eight pins is too much you could use a 4 bit interface.
    Still much faster than any I2C or serial EEPROM, particularly when you
    have to wait 10ms after a write cycle.

    If you read a value and then update that value, you are supposed to wait 10ms right there.

    No reason why the pic acting as a RAM chip couldn't perform other tasks until
    it is interrupted,
    as long as there's enough RAM left in both chips to run the program as well.

    I'm sure I've asked about external RAM on this board before (or on the old picbasic list).
    It would be nice to have a fast pic compatible RAM chip, as well as an FPU
    (another thing I've asked about).
    I'm sad that the pic32 chips don't even have an FPU (something I expected).
    Hi Art,

    I think the hardware SPI port might do it. I'm going to try these: http://www.mouser.com/ProductDetail/...1pcR43MBP1g%3d. I don't care so much that they're non-volatile but they are much faster at writing than standard EEPROM.

    Best,
    Paul

  5. #5
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    I still think you should have more than enough storage on an 18F452.
    Yeap, I must have been smoking something. No way to fit it in.

    The part you highlighted is very cool (fast as SRAM, but non-volatile like SEEPROM). The 16k part will be great for 1024 WORDS, but will only fit half of the 1204 LONGS.

  6. #6
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Followup

    Just wanted to followup with news of success. After a comedy of wiring errors I finally got an F-RAM going using shiftin and shiftout. Once I confirmed that as working I changed the code to use the hardware SPI port. It is blazingly fast. I'm using running the 18F452 at 20MHz so I can "only" run with a 5MHz clock. Haven't actually timed it (yet) but I think it'll all work out just fine.

    If there's any interest I'll post the code in the Code Examples section.

    Thanks again, everyone, for all the suggestions.

    Best Regards,
    Paul

  7. #7
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    I have used the i2c version of the FRAM and liked it. I had to switch when I needed more memory, though... it can cost over 10x the price of an atmel eeprom.

  8. #8
    Join Date
    May 2009
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by prstein View Post
    Just wanted to followup with news of success. After a comedy of wiring errors I finally got an F-RAM going using shiftin and shiftout. Once I confirmed that as working I changed the code to use the hardware SPI port. It is blazingly fast. I'm using running the 18F452 at 20MHz so I can "only" run with a 5MHz clock. Haven't actually timed it (yet) but I think it'll all work out just fine.

    If there's any interest I'll post the code in the Code Examples section.

    Thanks again, everyone, for all the suggestions.

    Best Regards,
    Paul
    Hi Paul: I am actually trying to figure out the hardware SPI module for F-RAM. So can you share your codes for that part? I appreciate it very much!!!

    Vinson

  9. #9
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hankshone View Post
    Hi Paul: I am actually trying to figure out the hardware SPI module for F-RAM. So can you share your codes for that part? I appreciate it very much!!!

    Vinson
    Hello Vinson,

    Here it is, warts and all...

    Code:
    '****************************************************************
    '*  Name    : HW_FRAM_SPI_Test.pbp                              *
    '*  Notes   : Demo of using hardware SPI port to read and write *
    '*          : a Ramtron FM25C106-G 16K 5V F-RAM chip.           *
    '*          :                                                   *
    '*          : Assembled on an Olimex DEV-00021 40-pin           *
    '*          : board from Sparkfun.                              *
    '*          :                                                   *
    '*          : Much information on working with the hardware     *
    '*          : SPI was gleaned from Jeremy Grotte's              *
    '*          : sdfshc32d.pbp file.                               *
    '*          :                                                   *
    '*          : Compiled using PBP v2.60L                         *
    '*          :                                                   *
    '****************************************************************
    
    ' PIC18F452 DIP Package
    ' Pin Assignments
    ' Pin # Use                 Hookup
    '  1    MCLR/VPP            To Vdd through 4.7k resistor
    '  2    RA0/AN0             n/c, reserved for analog input
    '  3    RA1/AN1             n/c
    '  4    RA2/AN2/VREF-       n/c
    '  5    RA3/AN3/VREF+       n/c
    '  6    RA4/T0CKI           n/c
    '  7    RA5/AN4/SS          n/c
    '  8    RE0/RD/AN5          n/c
    '  9    RE1/WR/AN6          n/c
    ' 10    RE2/CS/AN7          n/c
    ' 11    Vdd                 Power, +5V
    ' 12    Vss                 Ground
    ' 13    OSC1/CLKIN          To 20MHz crystal
    ' 14    OSC2/CLKOUT         To 20MHz crystal
    ' 15    RC0/T1OSO/T1CKI     n/c
    ' 16    RC1/T1OSI/CCP2    	n/c
    ' 17    RC2/CCP1            n/c
    ' 18    RC3/SCK/SCL         to F-RAM SCK (pin 6)
    ' 19    RD0/PSP0         	n/c
    ' 20    RD1/PSP1            n/c
    
    ' 21    RD2/PSP2            n/c
    ' 22    RD3/PSP3            FRAM_CS, to F-RAM CS (pin 1)
    ' 23    RC4/SDI/SDA         SDI, to F-RAM SO (pin 2)
    ' 24    RC5/SDO             SDO, to F-RAM SI (pin 5)
    ' 25    RC6/TX/CK           TX; to MAX232A Pin 11 (goes out from pin 14 to DB9F pin 2)
    ' 26    RC7/RX/DT           RX; to MAX232A Pin 12 (goes out from pin 13 to DB9F pin 3)
    ' 27    RD4/PSP4            n/c
    ' 28    RD5/PSP5            n/c
    ' 29    RD6/PSP6            n/c
    ' 30    RD7/PSP7            n/c
    ' 31    Vss                 Ground
    ' 32    Vdd                 Power, +5V
    ' 33    RB0/INT             n/c
    ' 34    RB1                 n/c
    ' 35    RB2                 n/c
    ' 36    RB3/PGM             n/c
    ' 37    RB4                 n/c
    ' 38    RB5                 n/c
    ' 39    RB6/PGC             n/c
    ' 40    RB7/PGD             n/c
    
    'Notes
    '-----
    'SETUP RS232:
    'Target device uses 115200 baud, 8 bits, 1 stop bit, flow control = none
    
    
    '--------------------------------------------------------------------------------
    '### Includes
    '--------------------------------------------------------------------------------
    'none
    
    
    '--------------------------------------------------------------------------------
    '### Defines
    '--------------------------------------------------------------------------------
    DEFINE LOADER_USED 1
    DEFINE OSC 20
    'Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h
    'Set transmit register to transmitter enabled, high speed BRGH
    DEFINE HSER_TXSTA 24h
    'Set baud rate
    DEFINE HSER_BAUD  115200
    'automatically clear any USART overflows
    DEFINE HSER_CLROERR 1 
    
    
    '--------------------------------------------------------------------------------
    '### Constants                                        
    '--------------------------------------------------------------------------------
    TRUE	CON 1
    FALSE	CON 0
    
    OCWREN	con %00000110	'F-RAM Write Enable Op-Code
    OCRDSR 	con %00000101	'F-RAM Read Status Register Op-Code
    OCWRSR 	con %00000001	'F-RAM Write Status Register Op-Code
    OCREAD	con %00000011	'F-RAM Read Memory Op-Code
    OCWRITE con %00000010	'F-RAM Write Memory Op-Code
    
    
    '--------------------------------------------------------------------------------
    '### Aliases
    '--------------------------------------------------------------------------------
    SCK				Var	PORTC.3	' SPI clock
    SCK_TRIS		Var	TRISC.3	' SPI clock direction
    
    SDI				Var	PORTC.4	' SPI data in
    SDI_TRIS		Var	TRISC.4	' SPI data in direction
    SDO				Var	PORTC.5	' SPI data out
    SDO_TRIS		Var	TRISC.5	' SPI data out direction
    
    FRAM_CS			Var	PORTD.3	' F-RAM chip select
    FRAM_CS_TRIS	Var	TRISD.3	' F-RAM chip select direction
    
    WCOL			Var	SSPCON1.7	' SSP write collision
    SSPEN			Var	SSPCON1.5	' SSP enable
    SSPIF			Var	PIR1.3		' SSP interrupt flag
    
    
    '--------------------------------------------------------------------------------
    '### Set Up Registers
    '--------------------------------------------------------------------------------
    ADCON1 = %10001110  'left justified, RA0/AN0 is analog input
    
    'Set up SPI port
    SSPSTAT = %01000000	' Sample at middle of data output time, Transmit on idle rising edge of SCK
    'SSPCON1 = %00000010	' SPI master mode, clock = Fosc/64, Clock idle LOW.
    'SSPCON1 = %00000001	' SPI master mode, clock = Fosc/16, Clock idle LOW.
    SSPCON1 = %00000000	' SPI master mode, clock = Fosc/4, Clock idle LOW.
    SSPEN = 1			' Enable hardware SPI port.
    
    
    '--------------------------------------------------------------------------------
    '### Variables
    '--------------------------------------------------------------------------------
    nSPI_Data_In	var byte
    nSPI_Data_Out	var byte
    lVal 			var	long
    wFRAM_Addr		var word
    
    
    '--------------------------------------------------------------------------------
    '### Initialization
    '--------------------------------------------------------------------------------
    FRAM_CS = 1		' F-RAM chip not selected.
    FRAM_CS_TRIS = 0' F-RAM chip select as output
    SDO = 1			' Start SPI data out high
    SDO_TRIS = 0	' SPI data out as Output
    SDI_TRIS = 1	' SPI data in as Input
    SCK = 0			' SPI clock idles low
    SCK_TRIS = 0	' SPI clock as Output
    
    wFRAM_Addr = $000F	' Set an arbitray memory location
    lVal = -5000		' Set lVal to some starting point
    
    pause 500
    
    hserout["lVal initalized to ", dec lVal,13,10]
    
    'Jump to Main program
    goto main
    
    
    '--------------------------------------------------------------------------------
    '### Helper Functions
    '--------------------------------------------------------------------------------
    WriteSPI:
    	WCOL = 0
    	nSPI_Data_In = SSPBUF	' Clear the buffer.
    	SSPIF = 0				' Clear the interrupt flag.
    	SSPBUF = nSPI_Data_Out	' Send the byte.
    	If (WCOL) Then Return	' Check for write collision.
    	While (!SSPIF)			' Wait for send to complete.
    	Wend
    Return
    
    ReadSPI:
    	nSPI_Data_In = SSPBUF	' Clear the buffer.
    	SSPIF = 0				' Clear the interrupt flag.
    	SSPBUF = $ff 			' Shift out a dummy byte.
    	While (!SSPIF)			' Wait for receive byte.
    	Wend
    	nSPI_Data_In = SSPBUF	' Get the byte.
    return
    
    
    '--------------------------------------------------------------------------------
    '### MAIN PROGRAM
    '--------------------------------------------------------------------------------
    Main:
    	' Do a write
    	' Select the F-RAM
    	FRAM_CS = 0
    	' Begin with WREN
    	nSPI_Data_Out = OCWREN
    	gosub WriteSPI
    	' un-select the F-RAM
    	FRAM_CS = 1	' only one Op-code per chip select!!!
    
    	' Select the F-RAM
    	FRAM_cs = 0
    	' Next send WRITE OpCode
    	nSPI_Data_Out = OCWrite
    	gosub WriteSPI
    
    	' Send two bytes of address (upper 5 bits are "don't care")
    	nSPI_Data_Out = wFRAM_Addr.HighByte	'$00
    	gosub WriteSPI
    	nSPI_Data_Out = wFRAM_Addr.LowByte	'$0f
    	gosub WriteSPI
    
    	' next byte(s) are data, address will increment with each write
    	nSPI_Data_Out = lVal.Byte0
    	gosub WriteSPI
    	nSPI_Data_Out = lVal.Byte1
    	gosub WriteSPI
    	nSPI_Data_Out = lVal.Byte2
    	gosub WriteSPI
    	nSPI_Data_Out = lVal.Byte3
    	gosub WriteSPI
    	' un-select the F-RAM
    	FRAM_CS = 1
    
    	' do a read
    	FRAM_CS = 0
    	' Begin by sending the read OpCode
    	nSPI_Data_Out = OCREAD '=READ command
    	gosub WriteSPI
    
    	' Send two bytes of address (upper 5 bits are "don't care")
    	nSPI_Data_Out = wFRAM_Addr.HighByte
    	gosub WriteSPI
    	nSPI_Data_Out = wFRAM_Addr.LowByte
    	gosub WriteSPI
    
    	' Now read in the value one byte at a time
    	gosub ReadSPI  'one byte into nSPI_Data_In
    	lVal.Byte0 = nSPI_Data_In
    	gosub ReadSPI  'one byte into nSPI_Data_In
    	lVal.Byte1 = nSPI_Data_In
    	gosub ReadSPI  'one byte into nSPI_Data_In
    	lVal.Byte2 = nSPI_Data_In
    	gosub ReadSPI  'one byte into nSPI_Data_In
    	lVal.Byte3 = nSPI_Data_In
    	FRAM_CS = 1
    
    	hserout["lVal=",dec lVal,13,10];
    
    	' Add one and write it back to the same location
    	lVal = lVal + 1
    goto Main
    Let us know if there are questions or difficulties.

    Best Regards,
    Paul

  10. #10
    Join Date
    May 2009
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by prstein View Post
    Just wanted to followup with news of success. After a comedy of wiring errors I finally got an F-RAM going using shiftin and shiftout. Once I confirmed that as working I changed the code to use the hardware SPI port. It is blazingly fast. I'm using running the 18F452 at 20MHz so I can "only" run with a 5MHz clock. Haven't actually timed it (yet) but I think it'll all work out just fine.

    If there's any interest I'll post the code in the Code Examples section.

    Thanks again, everyone, for all the suggestions.

    Best Regards,
    Paul
    Actually I could use SHIFTIN and SHIFTOUT for accessing the F-RAM memory, as you told, it is a "comedy" wiring error, it seems like totally reversed. But for hardware SPI, I think the MISO,MOSI connection should be followed, right? In your code, it is connected like this.

    Vinson

  11. #11
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hankshone View Post
    Actually I could use SHIFTIN and SHIFTOUT for accessing the F-RAM memory, as you told, it is a "comedy" wiring error, it seems like totally reversed. But for hardware SPI, I think the MISO,MOSI connection should be followed, right? In your code, it is connected like this.
    The only thing I don't like about SHIFTIN/SHIFTOUT is that they are so slow. But following advice from another thread (several threads actually) about SPI I used them to make sure everything was working in some fashion before I stepped up to the hardware SPI. Reversing the MISO/MOSI connections was just one of the many errors I started with. (I also spent an hour trying to figure out why I couldn't get *any* response from the F-RAM; turns out I hadn't actually installed the chip yet!)

    Best Regards,
    Paul

Similar Threads

  1. External memory routines?
    By John_Mac in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th April 2009, 02:13
  2. external Memory
    By jerryf in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th November 2008, 02:06
  3. PBP/PBPL and external memory
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th November 2007, 05:31
  4. PBP External Memory Bus Support
    By ALFRED in forum mel PIC BASIC
    Replies: 4
    Last Post: - 25th December 2006, 08:42
  5. external memory
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th April 2006, 00:51

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts