回复【4楼】正点原子:
---------------------------------
最新成果,可以读写了,但是写一次然后读一次可以读出数据,然后再写一次再读一次就读不出来,然后又再写一次就可以读出来
再更新!!!
void SPI_Flash_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOG, ENABLE );//PORTB时钟使能
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // PB12 推挽
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_12);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_8; // PD2 推挽
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOD,GPIO_Pin_2);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; // PG7 推挽
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_SetBits(GPIOG,GPIO_Pin_7);
SPI2_Init(); //初始化SPI
// SPI2_SetSpeed(SPI_BaudRatePrescaler_2);//设置为18M时钟,高速模式/************(去掉高速模式就好了,可能是太快了,我用的是25q16,)*************************/
SPI_FLASH_TYPE=SPI_Flash_ReadID();//读取FLASH ID.
} |