本帖最后由 jorry 于 2017-4-20 22:39 编辑
采用原子的代码,板子为硬件电路和原子该部分电路一样,但无法读出数据,单步提示图,调用代码如下#ifdef USING_FLASHDEVICE
const u8 TEXT_Buffer[]={"Explorer STM32F1 SPI TEST"};
#define SIZE sizeof(TEXT_Buffer)
u32 FLASH_SIZE=16*1024*1024; //FLASH ′óD¡Îa16×Ö½ú
u8 datatemp[SIZE];
#endif
#ifdef USING_FLASHDEVICE SPI_Flash_Init(); //SPI FLASH 3õê¼»ˉ
while(SPI_Flash_ReadID()!=W25Q128) //¼ì2a2»μ½W25Q128 ¿éòÔ¼ì2aμ½
{
USART1_Printfstr("Please Check!
");
delay_ms(100);
}
SPI_Flash_Write((u8*)TEXT_Buffer,FLASH_SIZE-100,SIZE); //′óμ1êyμú100¸öμØÖ·′|¿aê¼,D′èëSIZE3¤¶èμÄêy¾Y
delay_ms(100);
#endif
读取代码如下
#ifdef USING_FLASHDEVICE
SPI_Flash_Read(datatemp,FLASH_SIZE-100,SIZE); //′óμ1êyμú100¸öμØÖ·′|¿aê¼,¶á3öSIZE¸ö×Ö½ú
delay_ms(100);
sprintf(temp,"%s
",datatemp);
USART1_Printfstr(temp);
#endif
找不出问题,硬件经测量和原子电路一样,供电都为3.3V,请指导帮助!谢谢
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );//PORTBê±Öóê1Äü
RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );//SPI2ê±Öóê1Äü
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //PB13/14/15¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIOB
GPIO_SetBits(GPIOB,GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); //PB13/14/15éÏà-
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //éèÖÃSPIμ¥Ïò»òÕßË«ÏòμÄêy¾YÄ£ê½:SPIéèÖÃÎaË«ÏßË«Ïòè«Ë«1¤
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //éèÖÃSPI1¤×÷Ä£ê½:éèÖÃÎaÖ÷SPI
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //éèÖÃSPIμÄêy¾Y′óD¡:SPI·¢Ëí½óêÕ8λ֡½á11
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //′®DDí¬2½ê±ÖóμÄ¿ÕÏD×′ì¬Îa¸ßμçƽ
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //′®DDí¬2½ê±ÖóμÄμú¶t¸öìø±äÑØ£¨éÏéy»òϽ죩êy¾Y±»2éÑù
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSSDÅoÅóéó2¼t£¨NSS1ü½Å£©»1êÇèí¼t£¨ê1óÃSSI룩1üàí:Äú2¿NSSDÅoÅóDSSIλ¿ØÖÆ
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //¶¨òå2¨ìØÂêÔ¤·ÖÆμμÄÖμ:2¨ìØÂêÔ¤·ÖÆμÖμÎa256
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //Ö¸¶¨êy¾Y′«êä′óMSBλ»1êÇLSBλ¿aê¼:êy¾Y′«êä′óMSBλ¿aê¼
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRCÖμ¼ÆËãμĶàÏîê½
SPI_Init(SPI2, &SPI_InitStructure); //¸ù¾YSPI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèSPIx¼Ä′æÆ÷
SPI_Cmd(SPI2, ENABLE); //ê1ÄüSPIíaéè
SPI2_ReadWriteByte(0xff);//Æô¶ˉ′«êä
}
一周热门 更多>