w25q64的SPI引脚和w25x16一样,只不过把片选改了,求解惑啊
[mw_shl_code=c,true]#define SPI_FLASH_PageSize 256
#define SPI_FLASH_PerWritePageSize 256
/* Private define ------------------------------------------------------------*/
#define W25X_WriteEnable 0x06
#define W25X_WriteDisable 0x04
#define W25X_ReadStatusReg 0x05
#define W25X_WriteStatusReg 0x01
#define W25X_ReadData 0x03
#define W25X_FastReadData 0x0B
#define W25X_FastReadDual 0x3B
#define W25X_PageProgram 0x02
#define W25X_BlockErase 0xD8
#define W25X_SectorErase 0x20
#define W25X_ChipErase 0xC7
#define W25X_PowerDown 0xB9
#define W25X_ReleasePowerDown 0xAB
#define W25X_DeviceID 0xAB
#define W25X_ManufactDeviceID 0x90
#define W25X_JedecDeviceID 0x9F
#define WIP_FlagMask 0x01 /* Write In Progress (WIP) flag */
#define Dummy_Byte 0xA5
u32 SPI_FLASH_ReadID(void)
{
u32 Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0;
/*????SPI_FLASH??????????*/
SPI_FLASH_CS_LOW();
/* ×???????ID ?±?ò??·????ü??*/
SPI_FLASH_SendByte(W25X_JedecDeviceID);
Temp0 = SPI_FLASH_SendByte(Dummy_Byte);
Temp1 = SPI_FLASH_SendByte(Dummy_Byte);
Temp2 = SPI_FLASH_SendByte(Dummy_Byte);
/*????SPI_FLASH??????????*/
SPI_FLASH_CS_HIGH();
Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2;
return Temp;
}
void SPI_FLASH_Test(void)
{
__IO uint32_t FlashID = 0;
__IO uint32_t DeviceID = 0;
/*????SPI_Flash??ID*/
FlashID = SPI_FLASH_ReadID();
printf("
??????ID?? 0x%X", FlashID);
/* ??????????SPI_Flash??ID??·????· */
// if ((FlashID == W25X16_FLASH_ID))
{
/* ????SPI FLASH???????? */
SPI_FLASH_SectorErase(FLASH_SectorToErase);
printf("
????SPI FLASH????????: %s", Tx_Buffer);
/* ??Tx_Buffer??????SPI FLASH?? */
SPI_FLASH_BufferWrite(Tx_Buffer, FLASH_WriteAddress, BufferSize);
/* ??SPI FLASH??????????*/
SPI_FLASH_BufferRead(Rx_Buffer, FLASH_ReadAddress, BufferSize);
/* ?ì?é??????????????????????·????? */
TransferStatus1 = Buffercmp(Tx_Buffer, Rx_Buffer, BufferSize);
if(PASSED == TransferStatus1)
{
printf("
??????????????????????!
");
}
else
{
printf("
?í?ó-->????????????????????????!
");
}
/* ????SPI FLASH???????? */
SPI_FLASH_SectorErase(FLASH_SectorToErase);
/* ??SPI FLASH??????????*/
SPI_FLASH_BufferRead(Rx_Buffer, FLASH_ReadAddress, BufferSize);
/* ?ì?é??????????????·????· */
for (Index = 0; Index < BufferSize; Index++)
{
if (Rx_Buffer[Index] != 0xFF)
{
TransferStatus2 = FAILED;
}
}
if(PASSED == TransferStatus2)
{
printf("
?????ó??????????0xFF?????·!
");
}
else
{
printf("
?í?ó-->?????ó????????????0xFF!
");
}
if((PASSED == TransferStatus1) && (PASSED == TransferStatus2))
{
printf("
W25x16???????é????!
");
}
else
{
printf("
W25x16???????é?§°?!
");
}
}
// else
// {
// printf("
W25x16???????é?§°?!
");
// }
/*SPI FLASH????????????*/
SPI_Flash_PowerDown();
}[/mw_shl_code]
我的板子上是w25q16芯片,w25Q64的外围电路是照着这个弄得,应该合适的吧 怎么连ID都读不出来……板子上的芯片用惯了,实际用个芯片感觉好难!
---------------------------------
电路我测了没问题啊,和上面图中一样的。但是程序烧进去就是读写失败,我直接改了个CS片选,其他引脚和板子上的w25Q16共用SPI1引脚,为什么就是不行呢,大神有没有高招啊,教教我
一周热门 更多>