發新話題
打印

Flash 寫入讀出

Flash 寫入讀出

你好 請問一下目前我要測試把資料寫入
程式碼如下
EA = 0;
EraseChip(0x0F00);
PrgCode( 0x0F01, 1, 0x0f );
pread = (char code *) (0x0F01);
ver = *pread;
EA = 1;

PrgCode內寫入的資料目前是0x0F
但是只要寫入的數值超過0x0F
數值就會是0
請問有可能是什麼樣的情況呢
我所使用的MCU是Si1014

TOP

Hi!
你可能要再描述清楚你的問題.
PrgCode這函式是甚麼?他的code也請讓我們知道.
我想你有問題部份因該是PrgCode吧!
有可能這函式有些限制....


TOP

void EraseChip( unsigned short u16Address )
{
        PSCTL = 0x03;
        WriteByteToFlash( u16Address & 0xFE00, 0x00);

        PSCTL = 0x00;
}

unsigned char PrgCode(unsigned short iAddress, unsigned short u16Len, unsigned char *pu8Data)
{
        unsigned char cStatus;
        unsigned short Cnt;
        unsigned int iRealAddr;


        for (Cnt=0; Cnt<u16Len; Cnt++)
        {
                iRealAddr = iAddress + Cnt;

                PSCTL = 0x01;
                WriteByteToFlash(iRealAddr, pu8Data[Cnt]);
                PSCTL = 0x00;
                if (*(unsigned char code *)iRealAddr != pu8Data[Cnt])
                {
                        cStatus = 0xFF;
                        break;
                }
        }
        return cStatus;
}

void WriteByteToFlash(unsigned short iAddress, unsigned char cData)
{
        unsigned char data cByte =  cData;
        FLKEY = 0XA5;
        FLKEY = 0XF1;
        *(unsigned char xdata *)iAddress = cByte;
}

TOP

你可以到silabs 網站去下載
AN201 的文件
裡面有silabs 編寫好的 Flash Read/Write 程式可以提供你使用

https://www.silabs.com/products/mcu/Pages/ApplicationNotes.aspx

TOP

發新話題