Hi guys. Please help me with the code for Flash memory later I will give the code that I wrote. I can not even get the ID. It is very necessary code.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
namespace FlashClic
{
public class Program
{
static SPI sp;
static byte[] SERIAL_FLASH_CMD_WREN = {0x06};
static byte[] SERIAL_FLASH_CMD_RDSR={0x05};
static byte[] SERIAL_FLASH_CMD_READ = { 0x03 };
static byte[] SERIAL_FLASH_CMD_RDID = { 0x9f };
public static void Main()
{
OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false);
bool tiggle = false;
SPI.Configuration configSPI = new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.Di7, false, 0, 0, false, true,
10000, SPI.SPI_module.SPI1);
sp = new SPI(configSPI);
ReadID();
WriteFlash(1, 2);
ReadFlash(1);
while (true)
{
tiggle = !tiggle;
led.Write(tiggle);
Thread.Sleep(500);
}
}
public static void WriteFlash(UInt32 adress,int data)
{
sp.Write(SERIAL_FLASH_CMD_WREN);
byte[] adressByte = new byte[4];
byte[] dataByte = new byte[4];
byte[] dataSend = new byte[7];
adressByte = BitConverter.GetBytes(adress);
dataByte = BitConverter.GetBytes(data);
dataSend[6] = adressByte[2];
dataSend[5] = adressByte[1];
dataSend[4] = adressByte[0];
dataSend[3] = dataByte[3];
dataSend[2] = dataByte[2];
dataSend[1] = dataByte[1];
dataSend[0] = dataByte[0];
sp.Write(dataSend);
while (WriteBusy());
}
static bool WriteBusy()
{
byte[] writeOk = new byte [1];
sp.WriteRead(SERIAL_FLASH_CMD_RDSR, writeOk);
int C = writeOk[0];
C = C & 0x01;
if (C == 1) { return true; } else { return false; }
}
public static int ReadFlash(UInt32 adress){
sp.Write(SERIAL_FLASH_CMD_READ);
byte[] adressByte = new byte[4];
byte[] dataSend= new byte[3];
byte[] reciveData = new byte[4];
adressByte = BitConverter.GetBytes(adress);
dataSend[2] = adressByte[2];
dataSend[1] = adressByte[1];
dataSend[0] = adressByte[0];
sp.WriteRead(dataSend, reciveData);
int recive = BitConverter.ToInt32(reciveData);
return recive;
}
public static byte[] ReadID()
{
byte[] id = new byte[] { };
sp.WriteRead(SERIAL_FLASH_CMD_RDID, id);
return id;
}
}
}