STM32学习-22-[SPI]IO引脚初始化

SPI模块简介

SPI也属于片上外设

W25Q64简介

image

image

image

定位SPI引脚的位置

image

image

也有重映射IO口
image

其余几个自行查找
接线如图所示
image

选择IO引脚的模式

image

选择IO引脚的最大输出速度

image

image

void App_SPI1_Init(void){
	// 初始化IO引脚
	// 重映射
	RCC_APB2PeriphCLockCmd(RCC_APB2Periph_AFIO, ENABLE);
	GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);	// 对spi口进行重映射

	RCC_APB2PeriphCLockCmd(RCC_APB2Periph_GPIOB, ENABLE);
	RCC_APB2PeriphCLockCmd(RCC_APB2Periph_GPIOA, ENABLE);
	GPIO_InitTypeDef GPIO_InitStruct;

	// PB3 SCK AF_PP 2MHz
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOB, &GPIO_InitStruct);

	// PB4 MISO IPU
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_Init(GPIOB, &GPIO_InitStruct);

	// PB5 MOSI AF_PP 2MHz
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOB, &GPIO_InitStruct);

	// PA15 普通IONCC Out_PP 2MHz
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOA, &GPIO_InitStruct);
}
posted @ 2026-09-01 13:22  灵垚克府  阅读(6)  评论(0)    收藏  举报