How to use FRAM..?

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have just bought some FM25L256 FRAM for my ATMEGA16 AVR.

This is low voltage FRAM so I have put a buffer (74LCX125) in between, see diagram...

Are there anything a have to take care of or anything I have forgot in my diagram?
Because when i run this simple FRAM code I only get zero back, and I was supposed to get 170 back:

 int main(){

	DDRB = 0b10110000;  
	//  DDRB4 = chip select pin - output
	//  DDRB5 = MOSI pin - output
	//  DDRB6 = MISO pin - input
	//  DDRB7 = SCK pin - output 


	PORTB = 0b11111111;

        SPCR = (1<<SPE)|(1<<MSTR)|(1<<CPOL)|(1<<CPHA)|(1<<SPR0)|(1<<SPR1);
	SPSR = (0<<SPI2X);
	
	// SPE = Enable SPI
	// MSTR = Select SPI master mode
	// CPOL & CPHA = SPI mode 3
	
	TestWriteFRAM();
	TestReadFRAM();

}


//Transmit data through SPI interface
void spiTransmit(unsigned char data)
{
		
	SPDR = data; // start transmission

	while(!(SPSR & (1<<SPIF))); // Wait for transmission to complete
}



void TestWriteFRAM(){


			PORTB &= ~FRAM_CHIP_SELECT;// enable FRAM
			
			spiTransmit(FRAM_WREN); // opcode
			spiTransmit(FRAM_WRITE); // opcode
			spiTransmit(0); // upper adress bits
			spiTransmit(0); // lower adress bits
    			spiTransmit(177); // Data byte

					
			PORTB |= FRAM_CHIP_SELECT; // disable FRAM

			
}




void TestReadFRAM(){

			unsigned char data;
			PORTB &= ~FRAM_CHIP_SELECT;// enable FRAM
			
			spiTransmit(FRAM_READ);//opcode
			spiTransmit(0); // upper adress bits
			spiTransmit(0);// lower adress bits
	    		spiTransmit(0xFF); // Dummy byte

			data = SPDR; // Recieved data from FRAM
			
			PORTB |= FRAM_CHIP_SELECT; // disable FRAM

			usartSendData(data); // Sends data to the rs232 interface

}

See diagram here: http://www.gratisupload.dk/show....

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what does your scope show happening on the lines during the transfer?

(BTW a main() that ends? Never a great idea!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I havent measured at my scope.

But I have tried to static set the pins (portb pin4 = CS, portb pin5 = SCK, portb pin7 = mosi) to check that the voltage conversion is okay..

Put is it possible to check such a variating signal with a scope?

How would you do that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You're kidding right? I woudn't even *think* of wiring up to an SPI device without a scope or a logic analyser on the lines - you waste far too much time that way. These four lines switch between Gnd and Vcc as time passes - that's exactly what scopes/LAs are good at showing!

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put the probe on the pin, point eyeballs to cathode ray tube?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could also try reading the FM25L256 status register: it should return 0x80 if you test before opcode FRAM_WREN is sent.

And you have not grounded the FM25L256's WP# pin, have you? ;)

Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Everything seems fine on the signals..
Just some overshoot and undershoot on the square waves. But I dont think that is hurting the system..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No... The WP pin og HOLD pin is both connected to VCC.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
You could also try reading the FM25L256 status register: it should return 0x80 if you test before opcode FRAM_WREN is sent
.
I tried that and recieved nothing.

I simple can't get the FRAM to output anything? No matter what...
Nothing on the SO pin...

Maybe the chip is broken?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a silly question, but is 10kohm resistor okay, for pullup in this situation...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
is 10kohm resistor okay, for pullup in this situation...
IMHO the output of the 74LCX125 (which is not an open drain output) will always determine the actual voltage on that line: 0V or 3V. 10k will not be able to pull that strong 3V up to 5V.

A normal AVR input needs to be 0.6 * VCC = 3V to be read as high, in other words: 3V is on the limit.

Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
A normal AVR input needs to be 0.6 * VCC = 3V to be read as high, in other words: 3V is on the limit.

When I put the scope right at the Output line on the FRAM nothing is being outputtet. So that's not the problem... I have checked that the sigal corresponds perfectly to the signal I transmit from the AVR.
The FRAM simply won't respond with anything :-(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suggest to RTFM. You must deselect the memory after each operation before a new opcode can be issued.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks to me as if you do this, but I'll quote it anyway, from the Ramtron data sheet:

Quote:
Important: The /CS must go inactive after an operation is complete and before a new op-code can be issued. There is one valid op-code only per active chip select.

You might want to make sure the /CS line is actually going high between operations.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
You might want to make sure the /CS line is actually going high between operations.

Ya... everything seems fine on the signals.. Now I will try to exchange the chip with a new..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are the SPI bus very sensitive to overshoots?

Because a I have a 1volt over, og undershoot on the rising and falling edge of the clock to the FRAM. But it only lasts 100ns.
But the FRAM is looking at the signal on the rising edge, so maybe this will influence? But I am not sure, as it only lasts that short time.??

The FRAM wont even get damaged by this voltage, because it has maximum rating up to 5volt.

But the operating voltage is max 3.5volt. So I'm really not sure if the short overshoot could influence..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Quote:
You might want to make sure the /CS line is actually going high between operations.

Ya... everything seems fine on the signals.. Now I will try to exchange the chip with a new..

I think what peret means is this: an opcode is only allowed as the first byte after CS goes low (see datasheet). So you you need to toggle CS between the operation with opcode FRAM_WREN and the operation with opcode FRAM_WRITE. Like this:

void TestWriteFRAM(){

         //operation 1
         PORTB &= ~FRAM_CHIP_SELECT;// enable FRAM
         spiTransmit(FRAM_WREN); // opcode
         PORTB |= FRAM_CHIP_SELECT; // disable FRAM <<<

         //Maybe some delay here? <<<

         //operation 2
         PORTB &= ~FRAM_CHIP_SELECT;// enable FRAM <<<
         spiTransmit(FRAM_WRITE); // opcode
         spiTransmit(0); // upper adress bits
         spiTransmit(0); // lower adress bits
         spiTransmit(177); // Data byte
         PORTB |= FRAM_CHIP_SELECT; // disable FRAM

}

Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I think what peret means is this: an opcode is only allowed as the first byte after CS goes low (see datasheet). So you you need to toggle CS between the operation with opcode FRAM_WREN and the operation with opcode FRAM_WRITE. Like this:

Now I have tried with a delay too... And disable and enable like you described

Still doesn't work... And I have exchanged the chip also...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you tried reading the status register without any other operations?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Finally I found the problem...

First of all the readStatusregister command just output zero... So I thought the chip didn't work.

After I tried with your code again MartMega, first write then read. It finally worked. :-)

So the figure 9 in the Fm25L256 is correct, but you have to make a wren command beforce this and remember to set cs high and low again..

Thanks to all of you...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are right, I got the names WREN and WPEN mixed up... Sorry!

Martin.