我用W25Q16的读写函数测试w25Q64怎么总是失败?需要改动什么吗?

2019-07-21 05:59发布

 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都读不出来……板子上的芯片用惯了,实际用个芯片感觉好难!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
21条回答
正点原子
1楼-- · 2019-07-21 06:21
我们就有驱动W25Q64的代码,比如战舰板的SPI例程,参考下了。
LIUYABO
2楼-- · 2019-07-21 10:42
回复【12楼】八度空间:
---------------------------------
呵呵,谢谢你的解答,终于调出来了! 竟然是初始化时没有把SPI引脚拉高(GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);),但是试验箱上并没有拉高,为什么也可以出来?哈哈,反正出来了,字库终于写进去了!
八度空间
3楼-- · 2019-07-21 12:19
你这个函数的代码发上来看下SPI_FLASH_SendByte()
LIUYABO
4楼-- · 2019-07-21 17:51
回复【2楼】八度空间:
---------------------------------
u8 SPI_FLASH_SendByte(u8 byte)
{
    /* Loop while DR register in not emplty */
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);

    /* Send byte through the SPI1 peripheral */
    SPI_I2S_SendData(SPI1, byte);

    /* Wait to receive a byte */
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);

    /* Return the byte read from the SPI bus */
    return SPI_I2S_ReceiveData(SPI1);
}
LIUYABO
5楼-- · 2019-07-21 22:00
 精彩回答 2  元偷偷看……
八度空间
6楼-- · 2019-07-21 23:57
回复【4楼】LIUYABO:
---------------------------------
完全可以,管脚兼容的,华邦那几个厮

一周热门 更多>