怀疑配置有问题 但是又找不到问题在哪 用的SPI2 大佬们有H743 相关SPI配置的例程嘛 SPI配置部分源码如下:
SCSI0 SCLK
I1 MISO
I2 MOSI
I3 INT
H15或PH2 RST
H14
CS 信号测了下在读写时候是有拉低的, 但是 SCLK MISO MOSI 三个信号线都没有输出
SPI_HandleTypeDef SPI1_Handler;
void SPI_Configuration(void)
{
SPI1_Handler.Instance=SPI2;
SPI1_Handler.Init.Mode=SPI_MODE_MASTER;
SPI1_Handler.Init.Direction=SPI_DIRECTION_2LINES;
SPI1_Handler.Init.DataSize=SPI_DATASIZE_8BIT;
SPI1_Handler.Init.CLKPolarity=SPI_POLARITY_LOW;
SPI1_Handler.Init.CLKPhase=SPI_PHASE_1EDGE;
SPI1_Handler.Init.NSS=SPI_NSS_SOFT;
SPI1_Handler.Init.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2;
SPI1_Handler.Init.FirstBit=SPI_FIRSTBIT_MSB;
SPI1_Handler.Init.TIMode=SPI_TIMODE_DISABLE;
SPI1_Handler.Init.CRCCalculation=SPI_CRCCALCULATION_DISABLE;
SPI1_Handler.Init.CRCPolynomial=7;
HAL_SPI_Init(&SPI1_Handler);
__HAL_SPI_ENABLE(&SPI1_Handler);
SPI1_ReadWriteByte(0x00);
}
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_GPIOI_CLK_ENABLE(); //ê1ÄüGPIOAê±Öó
__HAL_RCC_SPI2_CLK_ENABLE(); //ê1ÄüSPI1ê±Öó
//PA5,6,7
GPIO_Initure.Pin=GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_Initure.Pull=GPIO_PULLUP; //éÏà-
GPIO_Initure.Speed=GPIO_SPEED_FREQ_VERY_HIGH; //¿ìËù
HAL_GPIO_Init(GPIOI,&GPIO_Initure);
}
void W5500_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_Initure;; //¿aÆôGPIOAê±Öó
__HAL_RCC_GPIOI_CLK_ENABLE(); //¿aÆôGPIOCê±Öó
__HAL_RCC_GPIOH_CLK_ENABLE();
/* W5500_RSTòy½Å3õê¼»ˉÅäÖÃ(PC5) */
GPIO_Initure.Pin = W5500_RST;
GPIO_Initure.Speed=GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_Initure.Pull=GPIO_PULLUP; //éÏà-
HAL_GPIO_Init(W5500_RST_PORT, &GPIO_Initure);
HAL_GPIO_WritePin(W5500_RST_PORT,W5500_RST,1);
/* 3õê¼»ˉCSòy½Å */
GPIO_Initure.Pin = W5500_SCS;
GPIO_Initure.Speed=GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP;
GPIO_Initure.Pull=GPIO_PULLUP; //éÏà-
HAL_GPIO_Init(W5500_SCS_PORT, &GPIO_Initure);
HAL_GPIO_WritePin(W5500_SCS_PORT,W5500_SCS,GPIO_PIN_SET);
/* W5500_INTòy½Å3õê¼»ˉÅäÖÃ(PC4) */
GPIO_Initure.Pin = W5500_INT;
GPIO_Initure.Mode = GPIO_MODE_IT_FALLING;
GPIO_Initure.Pull=GPIO_PULLUP;
HAL_GPIO_Init(W5500_INT_PORT, &GPIO_Initure);
/* Connect EXTI Line4 to PC4 */
HAL_NVIC_SetPriority(EXTI4_IRQn,6,0); //
HAL_NVIC_EnableIRQ(EXTI4_IRQn); //
}
一周热门 更多>