高中生
最后登录1970-1-1
在线时间 小时
注册时间2019-11-27
|
用了野火的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移植过来的,请教下哪里有问题啊
|
|