本帖最后由 cool_coder 于 2014-2-19 13:17 编辑
找了段写数据的参考代码: OSSemPend(pSemSpi2,0,&byRet);
if( FALSE == sFlash_Wait()){
OSSemPost(pSemSpi2);
return FALSE;
}
if(sFlash_read_sr() & 0x1C){
sFlash_protect(0);
if( FALSE == sFlash_Wait()){
OSSemPost(pSemSpi2);
return FALSE;
}
}
sFlash_enable();
sFlash_cmd(FLASH_WREN);
sFlash_disable();
sFlash_enable();
sFlash_cmd(byCmd);
pByte = (INT8U*)(&uiAddress);
SPI_SendByte(SPI2,pByte[2]);
SPI_SendByte(SPI2,pByte[1]);
SPI_SendByte(SPI2,pByte[0]);
uiIndex = 0;
uiAddr = uiAddress;
pByte = (INT8U*)pBuf;
do{
SPI_SendByte(SPI2,pByte[uiIndex]);
uiIndex++;
uiAddr++;
if(0 == (uiAddr & 0x000000ff)){
break;
}
}while(1);
sFlash_disable();
OSSemPost(pSemSpi2);
|