如题,用207单片机配置spi就是读不出来fm25cl64存储器,读出来全是0xff.现在按照V1.00库版本里的配置如下,仍然读出还是0xFF。我用103的spi1可以正常读取,把103的配置代码移植到207,修改相应的配置仍然度不对。请大神们看看我下面207的spi配置有没有错误,我找不出来问题了? nss关键配置为推挽输出。
void spi_flash_init(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource13, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// GPIO_SetBits(GPIOB, GPIO_Pin_12);
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_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(sFLASH_SPI, &SPI_InitStructure);
SPI_Cmd(sFLASH_SPI, ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
请问你的问题解决了吗,我现在也遇到和你一模一样的问题,读出来全是0x00...
uint16_t SPI_FLASH_ReadID(void)
{
uint16_t Temp = 0, Temp0 = 0, Temp1 = 0;
// ·¢ËíD′ê1ÄüÖ¸áî
SPI_FLASH_WriteEnable();
// Ƭѡà-μí
SPI_FLASH_CS_LOW();
// ·¢Ëí¶áè¡é豸IDÖ¸áî
SPI_FLASH_SendByte(RDID);
// ·¢Ëí24λμÄêy¾YÆeê¼μØÖ·
SPI_FLASH_SendByte((uint8_t)(0x000000 >> 16));
SPI_FLASH_SendByte((uint8_t)(0x000000 >> 8));
SPI_FLASH_SendByte((uint8_t)0x000000);
// ¶áé豸ID
Temp0 = SPI_FLASH_SendByte(DUMMY_BYTE);
Temp1 = SPI_FLASH_SendByte(DUMMY_BYTE);
// Ƭѡà-¸ß
SPI_FLASH_CS_HIGH();
Temp = (Temp0 << 8) | Temp1;
return Temp;
}
一周热门 更多>