驱动gd25q40b程序是参考正点原子的w25x16,发现两个芯片差不多,但是在读id的时候发现一个问题,把原子哥的读写函数返回字节改成u16,如下 u16 SPIx_ReadWriteByte(u8 TxData) { u8 retry=0; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) //检查指定的SPI标志位设置与否:发送缓存空标志位 { retry++; if(retry>200)return 0; } SPI_I2S_SendData(SPI1, TxData); //通过外设SPIx发送一个数据 retry=0; while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) //检查指定的SPI标志位设置与否:接受缓存非空标志位 { retry++; if(retry>200) return 0; } return SPI_I2S_ReceiveData(SPI1); //返回通过SPIx最近接收的数据 } 然后把读取id函数里面的Temp作如下改动就可以读取正确的id号,但是如果不改,读出来的数,低字节的数争取,高字节的数不对。 u16 SPI_Flash_ReadID(void) { u16 Temp = 0; SPI_FLASH_CS=0; SPIx_ReadWriteByte(0x90); //发送读取ID命令 SPIx_ReadWriteByte(0x00); SPIx_ReadWriteByte(0x00); SPIx_ReadWriteByte(0x00); // Temp|=SPIx_ReadWriteByte(0xFF) |
回复:spi 驱动gd25q40b芯片读写失败
void Init_Spi_Flash(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
/*!< sEE_CS_GPIO, sEE_MOSI_GPIO, sEE_MISO_GPIO and sEE_SCK_GPIO
Periph clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
/*!< sEE Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
/*!< Configure SCK pins: SCK */
GPIO_InitStructure.GPIO_Pin = SPI_CLK_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(SPI_PORT, &GPIO_InitStructure);
/*!< Configure SPI pins: MISO */
GPIO_InitStructure.GPIO_Pin = SPI_MISO_PIN;
GPIO_Init(SPI_PORT, &GPIO_InitStructure);
/*!< Configure SPI pins: MOSI */
GPIO_InitStructure.GPIO_Pin = SPI_MOSI_PIN;
GPIO_Init(SPI_PORT, &GPIO_InitStructure);
/*!< Configure SPI_CS_PIN pin: sEE_SPI Card CS pin */
GPIO_InitStructure.GPIO_Pin = SPI_CS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(SPI_PORT, &GPIO_InitStructure);
/* Connect PXx to SPI_SCK */
GPIO_PinAFConfig(SPI_PORT, GPIO_PinSource13,GPIO_AF_1);
/* Connect PXx to sEE_SPI_MISO */
GPIO_PinAFConfig(SPI_PORT, GPIO_PinSource14,GPIO_AF_1);
/* Connect PXx to sEE_SPI_MOSI */
GPIO_PinAFConfig(SPI_PORT, GPIO_PinSource15,GPIO_AF_1);
/*!< sEE SPI Config */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStructure);
SPI_Cmd(SPI2, ENABLE); /*!< sEE_SPI enable */
GPIO_SetBits(SPI_PORT,SPI_CS_PIN);
}
RE:spi 驱动gd25q40b芯片读写失败
Temp = Temp
回复:spi 驱动gd25q40b芯片读写失败
RE:spi 驱动gd25q40b芯片读写失败
RE:spi 驱动gd25q40b芯片读写失败
RE:spi 驱动gd25q40b芯片读写失败
RE:spi 驱动gd25q40b芯片读写失败
RE:spi 驱动gd25q40b芯片读写失败
RE:spi 驱动gd25q40b芯片读写失败