Go Down

Topic: Guestion about FRAM FM25V05 (Read 904 times) previous topic - next topic


Feb 16, 2012, 01:37 pm Last Edit: Feb 16, 2012, 06:45 pm by RCX1 Reason: 1
My board is Arduino Mega 1280 and used memory is FRAM FM25V05.

I used  code from http://arduino.cc/en/Tutorial/SPIEEPROM, but I did some modifications.

When I upload the code everything goes fine, but I dont understand that what I get to the serial port or are that ok? First serial prints hi and then only 0, 0, 0, 0 etc.

Code: [Select]

#define DATAOUT 51//MOSI
#define DATAIN  50//MISO
#define SPICLOCK  52//sck
#define SLAVESELECT 53//ss chip select

//FM25V05 Op-code Commands
#define WREN  6
#define WRDI  4
#define RDSR  5  
#define WRSR  1
#define READ  3
#define WRITE 2

byte eeprom_output_data;
byte eeprom_input_data=0;
byte clr;
int address=0;
//data buffer
char buffer [128];

void fill_buffer()
 for (int I=0;I<128;I++)

char spi_transfer(volatile char data)
 SPDR = data;                    // Start the transmission
 while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
 return SPDR;                    // return the received byte

void setup()

 pinMode(DATAIN, INPUT);
 digitalWrite(SLAVESELECT,HIGH); //disable device
 // SPCR = 01010000
 //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
 //sample on leading edge of clk,system clock/4 rate (fastest)
 SPCR = (1<<SPE)|(1<<MSTR);
 //fill buffer with data
 //fill eeprom w/ buffer
 spi_transfer(WREN); //write enable
 spi_transfer(WRITE); //write instruction
 spi_transfer((char)(address>> 8 ));   //send MSByte address first
 spi_transfer((char)(address));      //send LSByte address
 //write 128 bytes
 for (int I=0;I<64;I++)
   spi_transfer(buffer[I]); //write data byte
 digitalWrite(SLAVESELECT,HIGH); //release chip
 //wait for eeprom to finish writing

byte read_eeprom(int EEPROM_address)
 int data;
 spi_transfer(READ); //transmit read opcode
 spi_transfer((char)(EEPROM_address>>8 ));   //send MSByte address first
 spi_transfer((char)(EEPROM_address));      //send LSByte address
 data = spi_transfer(0xFF); //get data byte
 digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer
 return data;

void loop()
 eeprom_output_data = read_eeprom(address);
 if (address == 128)
   address = 0;
 delay(500); //pause for readability

So what's the main problem?


So what's the main problem?

Are you really right shifting smiley face places? The main problem is that you did not properly post your code (using the # icon), so it is unreadable.

That small font and light gray text doesn't help, either.
The art of getting good answers lies in asking good questions.


I'm Sorry about the previous bad post and smileys was mistake. :/

Go Up