野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2461|回复: 1

STM32F429+W5500+SPI4无法写入IP

[复制链接]
发表于 2023-3-24 21:24:23 | 显示全部楼层 |阅读模式
用了野火的103+W5500可以用调试助手实现回环测试,然后把代码移植到STM32F429的SPI4上就不行了,调试发现写入IP地址没有写成功,所以怀疑是配置问题,但是我看了没发现问题啊


/*定义SPI2作为W5500的硬件接口*/
#define WIZ_SPIx_GPIO_PORT      GPIOE                                                                                    /* GPIO端口                     */
#define WIZ_SPIx_GPIO_CMD       RCC_AHB1PeriphClockCmd
#define WIZ_SPIx_GPIO_CLK       RCC_AHB1Periph_GPIOE                    /* GPIO端口时钟                 */
#define WIZ_SPIx                SPI4                               /* 定义W5500所用的SPI接口       */
#define WIZ_SPIx_CLK_CMD        RCC_APB2PeriphClockCmd
#define WIZ_SPIx_CLK            RCC_APB2Periph_SPI4                /* 定义W5500所用的SPI接口时钟   */
#define WIZ_SPIx_SCLK           GPIO_Pin_12                                                             /* 定义W5500的时钟管脚          */
#define WIZ_SPIx_MISO           GPIO_Pin_13                                                             /* 定义W5500的MISO管脚          */
#define WIZ_SPIx_MOSI           GPIO_Pin_14                                                             /* 定义W5500的MOSI管脚          */
#define WIZ_SPIx_SCS          GPIO_Pin_11                                                             /* 定义W5500的片选管脚          */
#define WIZ_SPIx_SCS_PORT     GPIOE                                                                                     /* GPIO端口                     */
#define WIZ_SPIx_SCS_CLK      RCC_AHB1Periph_GPIOE                     /* GPIO端口时钟                 */
#define WIZ_RESET             GPIO_Pin_10                                                                        /* 定义W5500的RESET管脚         */
#define WIZ_SPIx_RESET_PORT   GPIOE                                                                                    /* GPIO端口                     */
#define WIZ_SPIx_RESET_CLK    RCC_AHB1Periph_GPIOE                     /* GPIO端口时钟                 */
#define WIZ_INT               GPIO_Pin_9                                                                        /* 定义W5500的INT管脚           */
#define WIZ_SPIx_INT_PORT     GPIOE                                                                              /* GPIO端口                     */
#define WIZ_SPIx_INT_CLK      RCC_AHB1Periph_GPIOE              /* GPIO端口时钟                 */



void gpio_for_w5500_config(void)
{
  SPI_InitTypeDef  SPI_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
       
  WIZ_SPIx_GPIO_CMD(WIZ_SPIx_RESET_CLK|WIZ_SPIx_INT_CLK, ENABLE);
  WIZ_SPIx_GPIO_CMD(WIZ_SPIx_GPIO_CLK|WIZ_SPIx_SCS_CLK, ENABLE);

  /*!< SPI_FLASH_SPI Periph clock enable */
  WIZ_SPIx_CLK_CMD(WIZ_SPIx_CLK, ENABLE);

  
  /*!< Configure SPI_FLASH_SPI pins: SCK */
  GPIO_InitStructure.GPIO_Pin = WIZ_SPIx_SCLK|WIZ_SPIx_MISO|WIZ_SPIx_MOSI;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
  GPIO_Init(WIZ_SPIx_GPIO_PORT, &GPIO_InitStructure);


  /*!< Configure SPI_FLASH_SPI_CS_PIN pin: SPI_FLASH Card CS pin */
  GPIO_InitStructure.GPIO_Pin = WIZ_SPIx_SCS;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
  GPIO_Init(WIZ_SPIx_SCS_PORT, &GPIO_InitStructure);

        GPIO_PinAFConfig(WIZ_SPIx_GPIO_PORT,WIZ_SPIx_SCLK,GPIO_AF_SPI4);
        GPIO_PinAFConfig(WIZ_SPIx_GPIO_PORT,WIZ_SPIx_MISO,GPIO_AF_SPI4);
        GPIO_PinAFConfig(WIZ_SPIx_GPIO_PORT,WIZ_SPIx_MOSI,GPIO_AF_SPI4);
  /* SPI4 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_256;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(WIZ_SPIx, &SPI_InitStructure);
  SPI_Cmd(WIZ_SPIx, ENABLE);
       
  /*定义RESET引脚*/
  GPIO_InitStructure.GPIO_Pin = WIZ_RESET;                                               /*选择要控制的GPIO引脚*/                 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                     /*设置引脚速率为50MHz */               
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;                     /*设置引脚模式为通用推挽输出*/       
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
  GPIO_Init(WIZ_SPIx_RESET_PORT, &GPIO_InitStructure);                 /*调用库函数,初始化GPIO*/
  GPIO_SetBits(WIZ_SPIx_RESET_PORT, WIZ_RESET);               
  /*定义INT引脚*/       
  GPIO_InitStructure.GPIO_Pin = WIZ_INT;                                                       /*选择要控制的GPIO引脚*/                 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                     /*设置引脚速率为50MHz*/               
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;                                     /*设置引脚模式为通用推挽模拟上拉输入*/       
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
  GPIO_Init(WIZ_SPIx_INT_PORT, &GPIO_InitStructure);                         /*调用库函数,初始化GPIO*/
}

都是从野火103移植过来的,请教下哪里有问题啊
回复

使用道具 举报

发表于 2023-3-29 07:45:28 | 显示全部楼层
启动前复位没有
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-24 00:59 , Processed in 0.034890 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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