【晒FRAM铁电存储器样片】+新唐M058S测试读写FRAM MB85RS64
- UID
- 1030014
|
|
|
|
|
|
- UID
- 1030014
|
uint8_t SpiRead(void)
//主机在SCK下降沿,从MISO上读取1字节
{
uint8_t i;
for(i=0;i<8;i++)
{
DATA_BUF = DATA_BUF<<1;
MB85RS64_SCK = 1;
if(MB85RS64_MISO)
{
DATA_BUF+=1;
}
else
{
DATA_BUF+=0;
}
MB85RS64_SCK = 0;
}
return DATA_BUF;
}
void SpiWrite(uint8_t byte)
//主机向MOSI写1字节,设备在SCK上升沿读取
{
uint8_t i;
DATA_BUF = byte;
MB85RS64_SCK = 0;
for(i=0;i<8;i++)
{
if(DATA_BUF >> 7)
{
MB85RS64_MOSI = 1;
}
else
{
MB85RS64_MOSI = 0;
}
#if 1
MB85RS64_SCK = 1;
DATA_BUF = DATA_BUF << 1;
MB85RS64_SCK = 0;
#else
MB85RS64_SCK = 0;
MB85RS64_SCK = 1;
DATA_BUF = DATA_BUF << 1;
#endif
}
}
void SetWriteEnableLatch(void)
//OP CODE: 0000 0110
{
MB85RS64_CS = 0;
SpiWrite(0x06);
MB85RS64_CS = 1;
}
void ResetWriteEnableLatch(void)
//OP CODE: 0000 0100
{
MB85RS64_CS = 0;
SpiWrite(0x04);
MB85RS64_CS = 1;
}
uint8_t ReadStatusRegister(void)
//OP CODE: 0000 0101
{
uint8_t rsr_byte;
MB85RS64_CS = 0;
SpiWrite(0x05);
rsr_byte = SpiRead();
MB85RS64_CS = 1;
return rsr_byte;
}
void WriteStatusRegister(uint8_t wsr_byte)
//OP CODE: 0000 0001
{
uint8_t rsr_byte;
MB85RS64_CS = 0;
SpiWrite(0x01);
SpiWrite(wsr_byte);
MB85RS64_CS = 1;
}
uint8_t ReadMemoryCode(uint16_t addr)
//OP CODE: 0000 0011
{
uint8_t rmc_byte;
uint8_t addr_high, addr_low;
addr_high = (uint8_t)(addr&0xff00)>>8;
addr_low = (uint8_t)(addr&0x00ff);
MB85RS64_CS = 0;
SpiWrite(0x03);
SpiWrite(addr_high);
SpiWrite(addr_low);
rmc_byte = SpiRead();
MB85RS64_CS = 1;
return rmc_byte;
}
void WriteMemoryCode(uint16_t addr, uint8_t wmc_byte)
//OP CODE: 0000 0010
{
uint8_t addr_high, addr_low;
addr_high = (uint8_t)(addr&0xff00)>>8;
addr_low = (uint8_t)(addr&0x00ff);
MB85RS64_CS = 0;
SpiWrite(0x02);
SpiWrite(addr_high);
SpiWrite(addr_low);
SpiWrite(wmc_byte);
MB85RS64_CS = 1;
}
void FRAM_Operate(void)
{
uint8_t status = 0xab;
uint8_t arraydata[5];
uint8_t writedata[5];
uint16_t i;
memcpy(writedata, "\xaa\xbb\xcc\xdd\xee", 5);
memcpy(arraydata, "\x01\x02\x03\x04\x05", 5);
TRACE("------- before Read ---------\r\n");
TRACE("status = 0x%02x", status);
printbuf("arraydata", arraydata, sizeof(arraydata));
SetWriteEnableLatch();
status = ReadStatusRegister();
for(i=0;i<sizeof(arraydata);i++)
{
arraydata[i] = ReadMemoryCode(i);
}
TRACE("------- after Read ---------\r\n");
TRACE("status = 0x%02x", status);
printbuf("arraydata", arraydata, sizeof(arraydata));
for(i=0;i<sizeof(writedata);i++)
{
SetWriteEnableLatch();
WriteMemoryCode(i, writedata[i]);
}
TRACE("\r\n------- after Write writedata ---------");
printbuf("writedata", writedata, sizeof(writedata));
TRACE("------- after Read again ---------");
memset(arraydata, 0x00, sizeof(arraydata));
for(i=0;i<sizeof(arraydata);i++)
{
arraydata[i] = ReadMemoryCode(i);
}
printbuf("arraydata", arraydata, sizeof(arraydata));
} |
|
|
|
|
|
- UID
- 1030014
|
既然是模拟SPI,涉及到的CS, MOSI, MISO, SCK可以自由设定了,注意MISO,设置成输入模式 |
|
|
|
|
|
- UID
- 1030460
|
铁电存储器擦写次数可达到10的12次方,性能稳定,可靠性比较好. |
|
|
|
|
|