Hi, i can't write and read on my new F-RAM chip 4mbit by mi Teensy 3.2
There isn't a specific library for this component and i can't write a working sketch..
Someone that have experience about F-RAM??
The problem is the 3 byte addressing and the specific system or read / write command i think..
The chip is: CY15B104Q 4-Mbit 512K X 8 Serial SPI F-RAM
Datasheet:
http://www.mouser.com/ds/2/100/001-94240_CY15B104Q_4-Mbit_512_K_8_Serial_SPI_F-RA-914618.pdf
write code
Read code
There isn't a specific library for this component and i can't write a working sketch..
Someone that have experience about F-RAM??
The problem is the 3 byte addressing and the specific system or read / write command i think..
The chip is: CY15B104Q 4-Mbit 512K X 8 Serial SPI F-RAM
Datasheet:
http://www.mouser.com/ds/2/100/001-94240_CY15B104Q_4-Mbit_512_K_8_Serial_SPI_F-RA-914618.pdf
write code
Code:
#define DATAOUT 7//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 14//sck
#define SLAVESELECT 6//ss
//opcodes
#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;
unsigned int address=0;
byte daten=0;
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()
{
Serial.begin(9600);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,HIGH); //disable device
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
digitalWrite(SLAVESELECT,LOW);
spi_transfer(WREN); //write enable
digitalWrite(SLAVESELECT,HIGH);
delay(10);
Serial.print("starttime: ");
Serial.println(micros());
digitalWrite(SLAVESELECT,LOW); // write 32kByte in sequence
spi_transfer(WRITE); //write instruction
address=0;
spi_transfer((char)(address>>8)); //send MSByte address first
spi_transfer((char)(address)); //send LSByte address
// write 32KByte
for (unsigned int I=0;I<524288;I++)
{
spi_transfer(I/256); //write data byte
}
digitalWrite(SLAVESELECT,HIGH); //release chip
Serial.print("endtime: ");
Serial.println(micros()); Serial.println();
Serial.println("FRAM Write finish");
}
void loop()
{
delay(5000); //pause for readability
}
Read code
Code:
#define DATAOUT 7//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 14//sck
#define SLAVESELECT 6//ss
//opcodes
#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;
unsigned int address=0;
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
}
byte read_eeprom(int EEPROM_address)
{
//READ EEPROM
int data;
digitalWrite(SLAVESELECT,LOW);
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 setup()
{
Serial.begin(9600);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,HIGH); //disable device
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
}
void loop()
{
Serial.print('\n',BYTE);
for (unsigned int I=0;I<524288;I++)
{
eeprom_output_data = read_eeprom(I);
Serial.print(eeprom_output_data,DEC);
address++;
if (address == 64)
{Serial.print('\n',BYTE);
address = 0;
}
}
delay(5000); //pause for readability
}