高级会员

- 积分
- 770
- 金钱
- 770
- 注册时间
- 2013-4-23
- 在线时间
- 163 小时
|
1金钱
用了103+W5500可以用调试助手实现回环测试,然后把代码移植到STM32F429的SPI4上就不行了,调试发现写入IP地址没有写成功,然后看了43脚SPI4的SCLK没有输出,怀疑是不是SPI配置不对,但是反复对照几遍还是没找到问题,所以特来请教
/*定义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;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI4,ENABLE);
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);
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_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(WIZ_SPIx_GPIO_PORT, &GPIO_InitStructure);
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_SetBits(WIZ_SPIx_SCS_PORT,WIZ_SPIx_SCS);
/* 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_CPOL_Low SPI_CPOL_High
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//SPI_CPHA_1Edge SPI_CPHA_2Edge
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(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*/
}
|
|