OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5397|回复: 6

STM32F207 SPI Flash操作中,读出的数据为0x00,求解答!!!急

[复制链接]

9

主题

103

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
228
金钱
228
注册时间
2016-7-4
在线时间
47 小时
发表于 2016-7-4 11:23:29 | 显示全部楼层 |阅读模式
3金钱
SPI配置代码如下:
#define SPI_FLASH_SPI                              SPI1
#define SPI_FLASH_SPI_CLK                          RCC_APB2Periph_SPI1
#define SPI_FLASH_SPI_SCK_PIN                      GPIO_Pin_3                      /* PB.03 */
#define SPI_FLASH_SPI_SCK_GPIO_PORT                GPIOB                                                /* GPIOB */
#define SPI_FLASH_SPI_SCK_GPIO_CLK                 RCC_AHB1Periph_GPIOB
#define SPI_FLASH_SPI_MISO_PIN                     GPIO_Pin_4                                        /* PB.04 */
#define SPI_FLASH_SPI_MISO_GPIO_PORT               GPIOB                                                /* GPIOB */
#define SPI_FLASH_SPI_MISO_GPIO_CLK                RCC_AHB1Periph_GPIOB
#define SPI_FLASH_SPI_MOSI_PIN              GPIO_Pin_5                      /* PB.05 */
#define SPI_FLASH_SPI_MOSI_GPIO_PORT               GPIOB                           /* GPIOB */
#define SPI_FLASH_SPI_MOSI_GPIO_CLK                RCC_AHB1Periph_GPIOB
#define SPI_FLASH_CS_PIN                    GPIO_Pin_15                      /* PA.15 */
#define SPI_FLASH_CS_GPIO_PORT                     GPIOA                                                 /* GPIOA */
#define SPI_FLASH_CS_GPIO_CLK                      RCC_AHB1Periph_GPIOA


void S25FL132K_SPI_FLASH_Init(void)
{

        GPIO_InitTypeDef GPIO_InitStructure;
        SPI_InitTypeDef  SPI_InitStructure;
                 
        /*!< Deselect the FLASH: Chip Select high */
        S25FL132K_SPI_FLASH_CS_HIGH();
       
        /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO
                 and sFLASH_SPI_SCK_GPIO Periph clock enable */
        RCC_APB2PeriphClockCmd(SPI_FLASH_SPI_SCK_GPIO_CLK | SPI_FLASH_SPI_MISO_GPIO_CLK | SPI_FLASH_SPI_MOSI_GPIO_CLK |
                                        SPI_FLASH_CS_GPIO_CLK, ENABLE);
       
        /*!< sFLASH_SPI Periph clock enable */
        RCC_APB2PeriphClockCmd(SPI_FLASH_SPI_CLK, ENABLE);
       
        /*!< Configure sFLASH_SPI pins: SCK */
        GPIO_InitStructure.GPIO_Pin = SPI_FLASH_SPI_SCK_PIN;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
        GPIO_Init(SPI_FLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
       
        /*!< Configure sFLASH_SPI pins: MISO */
        GPIO_InitStructure.GPIO_Pin = SPI_FLASH_SPI_MISO_PIN;
        GPIO_Init(SPI_FLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
       
        /*!< Configure sFLASH_SPI pins: MOSI */
        GPIO_InitStructure.GPIO_Pin = SPI_FLASH_SPI_MOSI_PIN;
        GPIO_Init(SPI_FLASH_CS_GPIO_PORT, &GPIO_InitStructure);
       
        /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
        GPIO_InitStructure.GPIO_Pin = SPI_FLASH_CS_PIN;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_Init(SPI_FLASH_CS_GPIO_PORT, &GPIO_InitStructure);

        /*!< SPI configuration */
        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_Low;
        SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
        SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
        SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
        SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
        SPI_InitStructure.SPI_CRCPolynomial = 7;
        SPI_Init(SPI_FLASH_SPI, &SPI_InitStructure);

        /*!< Enable the sFLASH_SPI  */
        SPI_Cmd(SPI_FLASH_SPI, ENABLE);
}

//读取ID时为0x00
u32 S25FL132K_SPI_FLASH_ReadID(void)
{
        u32 Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0;
        S25FL132K_SPI_FLASH_WriteEnable();
        /* Select the FLASH: Chip Select low */
        S25FL132K_SPI_FLASH_CS_LOW();

        /* Send "RDID " instruction */
        S25FL132K_SPI_FLASH_SendByte(S25FL132K_JedecDeviceID);

        /* Read a byte from the FLASH */
        Temp0 = S25FL132K_SPI_FLASH_SendByte(Dummy_Byte);

        /* Read a byte from the FLASH */
        Temp1 = S25FL132K_SPI_FLASH_SendByte(Dummy_Byte);

        /* Read a byte from the FLASH */
        Temp2 = S25FL132K_SPI_FLASH_SendByte(Dummy_Byte);

        /* Deselect the FLASH: Chip Select high */
        S25FL132K_SPI_FLASH_CS_HIGH();

        Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2;

        return Temp;
}

跪求大神指点!!!


最佳答案

查看完整内容[请看2#楼]

GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; SPI_I2S_DeInit(SPI_FLASH_SPI); vTaskDelay(500); /*!< SPI_FLASH_SPI_CLK Periph clock enable */ RCC_APB2PeriphClockCmd(SPI_FLASH_SPI_CLK, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /*!< Configure pins: SCK MOIS MIOS*/ GPIO_Init ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

9

主题

103

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
228
金钱
228
注册时间
2016-7-4
在线时间
47 小时
 楼主| 发表于 2016-7-4 11:23:30 | 显示全部楼层
        GPIO_InitTypeDef GPIO_InitStructure;
        SPI_InitTypeDef  SPI_InitStructure;
       
        SPI_I2S_DeInit(SPI_FLASH_SPI);
        vTaskDelay(500);
       
        /*!< SPI_FLASH_SPI_CLK Periph clock enable */
        RCC_APB2PeriphClockCmd(SPI_FLASH_SPI_CLK, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
       
        /*!< Configure pins: SCK MOIS MIOS*/
        GPIO_InitStructure.GPIO_Pin = SPI_FLASH_SPI_SCK_PIN | SPI_FLASH_SPI_MISO_PIN | SPI_FLASH_SPI_MOSI_PIN;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(SPI_FLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
               
        GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI1);//Connect SPI pins to AF5
        GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI1);
        GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI1);
       
        /*!< Configure SPI_FLASH_CS_PIN pin: sFLASH Card CS pin */       
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_Pin = SPI_FLASH_CS_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(SPI_FLASH_CS_GPIO_PORT, &GPIO_InitStructure);
       
        /*!< Deselect the FLASH: Chip Select high */
        S25FL132K_SPI_FLASH_CS_HIGH();
       
        /*!< SPI configuration */
        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_32;
        SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
        SPI_InitStructure.SPI_CRCPolynomial = 7;
        SPI_Init(SPI_FLASH_SPI, &SPI_InitStructure);
       
        /*!< Enable the SPI_FLASH_SPI  */
        SPI_Cmd(SPI_FLASH_SPI, ENABLE);
上述是成功的配置代码,自己搞定了
回复

使用道具 举报

58

主题

6294

帖子

1

精华

资深版主

Rank: 8Rank: 8

积分
11546
金钱
11546
注册时间
2014-4-1
在线时间
1315 小时
发表于 2016-7-4 11:42:54 | 显示全部楼层

没用过这类器件。

一般来说,先要查各信号波形,
至少保证CPU发出的波形是正确的。

然后先调试读取程序(先不涉及写操作),
在器件里找个内容已知的存储单元,
读取它,数值必须等于已知的值。

读取成功以后,再调试写程序。


回复

使用道具 举报

9

主题

103

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
228
金钱
228
注册时间
2016-7-4
在线时间
47 小时
 楼主| 发表于 2016-7-4 11:56:44 | 显示全部楼层
xuande 发表于 2016-7-4 11:42
没用过这类器件。

一般来说,先要查各信号波形,

现在就是读取已知的deviceID,读出来是0x00
回复

使用道具 举报

9

主题

103

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
228
金钱
228
注册时间
2016-7-4
在线时间
47 小时
 楼主| 发表于 2016-7-5 08:32:27 | 显示全部楼层
顶起来啊
回复

使用道具 举报

9

主题

103

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
228
金钱
228
注册时间
2016-7-4
在线时间
47 小时
 楼主| 发表于 2016-7-5 08:32:38 | 显示全部楼层
顶起来啊
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-7-6 22:05:34 | 显示全部楼层
帮顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-10 13:37

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表