在线时间0 小时
UID117845
ST金币0
蝴蝶豆0
注册时间2009-3-23
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
控制stm32F207vc开发板中的spi1(master),无法输出clock,请教大侠们!
#ifdef OpenSPI1
#define Open207V_SPIx SPI1
#define Open207V_SPIx_CLK RCC_APB2Periph_SPI1
#define Open207V_SPIx_IRQn SPI1_IRQn
#define Open207V_SPIx_IRQHANDLER SPI1_IRQHandler
#define Open207V_SPIx_SCK_PIN GPIO_Pin_5
#define Open207V_SPIx_SCK_GPIO_PORT GPIOA
#define Open207V_SPIx_SCK_GPIO_CLK RCC_AHB1Periph_GPIOA
#define Open207V_SPIx_SCK_SOURCE GPIO_PinSource5
#define Open207V_SPIx_SCK_AF GPIO_AF_SPI1
#define Open207V_SPIx_MISO_PIN GPIO_Pin_6
#define Open207V_SPIx_MISO_GPIO_PORT GPIOA
#define Open207V_SPIx_MISO_GPIO_CLK RCC_AHB1Periph_GPIOA
#define Open207V_SPIx_MISO_SOURCE GPIO_PinSource6
#define Open207V_SPIx_MISO_AF GPIO_AF_SPI1
#define Open207V_SPIx_MOSI_PIN GPIO_Pin_5
#define Open207V_SPIx_MOSI_GPIO_PORT GPIOB
#define Open207V_SPIx_MOSI_GPIO_CLK RCC_AHB1Periph_GPIOB
#define Open207V_SPIx_MOSI_SOURCE GPIO_PinSource5
#define Open207V_SPIx_MOSI_AF GPIO_AF_SPI1
#endif
初始化函数如下:
{
SPI_InitTypeDef SPI_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(Open207V_SPIx_SCK_GPIO_CLK | Open207V_SPIx_MISO_GPIO_CLK | Open207V_SPIx_MOSI_GPIO_CLK,ENABLE);
#ifdef OpenSPI1
RCC_APB2PeriphClockCmd(Open207V_SPIx_CLK,ENABLE);
#else
RCC_APB1PeriphClockCmd(Open207V_SPIx_CLK,ENABLE);
#endif
GPIO_PinAFConfig(Open207V_SPIx_SCK_GPIO_PORT, Open207V_SPIx_SCK_SOURCE, Open207V_SPIx_SCK_AF);
GPIO_PinAFConfig(Open207V_SPIx_MISO_GPIO_PORT, Open207V_SPIx_MISO_SOURCE, Open207V_SPIx_MISO_AF);
GPIO_PinAFConfig(Open207V_SPIx_MOSI_GPIO_PORT, Open207V_SPIx_MOSI_SOURCE, Open207V_SPIx_MOSI_AF);
GPIO_InitStructure.GPIO_Pin = Open207V_SPIx_SCK_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(Open207V_SPIx_SCK_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open207V_SPIx_MISO_PIN;
GPIO_Init(Open207V_SPIx_MISO_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open207V_SPIx_MOSI_PIN;
GPIO_Init(Open207V_SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure);
SPI_I2S_DeInit(Open207V_SPIx);
SPI_InitStruct.SPI_Direction= SPI_Direction_2Lines_FullDuplex;
SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low ;
SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStruct.SPI_NSS = SPI_NSS_Soft ;
SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStruct.SPI_CRCPolynomial = 7;
SPI_Init(Open207V_SPIx, &SPI_InitStruct);
SPI_Cmd(Open207V_SPIx, ENABLE);
}
如果我将SPI1_SCK引脚换成PB3的功能引脚,则有clock输出,很奇怪为什么PA5这个引脚无法输出clock,已经确定该引脚没有复用,看了下手册该引脚IO结构是TTa的,不知道是啥意思? |
|