上图是外设的SPI波形图
STM32F107的配置如下:
能看到MCLK和MOSI,CS的波形,怎么就没有回应呢??
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//关闭jtag , 开启swd
/* 使能SPI1和GPIOA、GPIOB的RCC时钟*/
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//RCC_APB1Periph_SPI3
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SPI3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
SPI_Cmd(SPI3,DISABLE);
/*!初始化时钟信号线SCK */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PC10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/*初始化SPI_FLASH_SPI管脚: MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;//PC12
GPIO_Init(GPIOC, &GPIO_InitStructure);
/*初始化SPI_FLASH_SPI管脚: MISO */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PC11
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;//GPIO_Mode_Out_OD;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/*初始化片选信号管脚: /CS*/
#if 1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;//PA4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#endif
#if 1
/*拉高片选信号*/
SPI_FLASH_CS_HIGH();
/* SPI1初始化配置*/
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //主从模式选择,SCK信号有主机产生
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //SPI通信数据的大小
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //时钟极性
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //时钟相位
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//SPI_NSS_Soft; //片选信号,硬件模式还是软件模式
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128; //SPI分频值,分频后的值为SCK的时钟频率
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //选择SPI通信时,是高位数据在前还是低位数据在前
SPI_InitStructure.SPI_CRCPolynomial = 0; //与CRC校验有关
SPI_Init(SPI3, &SPI_InitStructure);
/*使能SPI1 */
SPI_Cmd(SPI3, ENABLE);
/*唤醒SPI FLASH*/
//SPI_Flash_WAKEUP();
#endif
一周热门 更多>