有哪位大神在搞STM32 的spi通信 急!!!!!!
2个回答
展开全部
有啊,我用DMA,还有普通模式都有用。给你普通模式吧。STM32f207的,10X的也类似:
SPI_InitTypeDef SPI_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(Open207Z_SPIx_SCK_GPIO_CLK | Open207Z_SPIx_MISO_GPIO_CLK | Open207Z_SPIx_MOSI_GPIO_CLK,ENABLE);
#ifdef OpenSPI1
RCC_APB2PeriphClockCmd(Open207Z_SPIx_CLK,ENABLE);
#else
RCC_APB1PeriphClockCmd(Open207Z_SPIx_CLK,ENABLE);
#endif
GPIO_PinAFConfig(Open207Z_SPIx_SCK_GPIO_PORT, Open207Z_SPIx_SCK_SOURCE, Open207Z_SPIx_SCK_AF);
GPIO_PinAFConfig(Open207Z_SPIx_MISO_GPIO_PORT, Open207Z_SPIx_MISO_SOURCE, Open207Z_SPIx_MISO_AF);
GPIO_PinAFConfig(Open207Z_SPIx_MOSI_GPIO_PORT, Open207Z_SPIx_MOSI_SOURCE, Open207Z_SPIx_MOSI_AF);
GPIO_InitStructure.GPIO_Pin = Open207Z_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(Open207Z_SPIx_SCK_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open207Z_SPIx_MISO_PIN;
GPIO_Init(Open207Z_SPIx_MISO_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open207Z_SPIx_MOSI_PIN;
GPIO_Init(Open207Z_SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure);
SPI_I2S_DeInit(Open207Z_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(Open207Z_SPIx, &SPI_InitStruct);
SPI_Cmd(Open207Z_SPIx, ENABLE);
SPI_InitTypeDef SPI_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(Open207Z_SPIx_SCK_GPIO_CLK | Open207Z_SPIx_MISO_GPIO_CLK | Open207Z_SPIx_MOSI_GPIO_CLK,ENABLE);
#ifdef OpenSPI1
RCC_APB2PeriphClockCmd(Open207Z_SPIx_CLK,ENABLE);
#else
RCC_APB1PeriphClockCmd(Open207Z_SPIx_CLK,ENABLE);
#endif
GPIO_PinAFConfig(Open207Z_SPIx_SCK_GPIO_PORT, Open207Z_SPIx_SCK_SOURCE, Open207Z_SPIx_SCK_AF);
GPIO_PinAFConfig(Open207Z_SPIx_MISO_GPIO_PORT, Open207Z_SPIx_MISO_SOURCE, Open207Z_SPIx_MISO_AF);
GPIO_PinAFConfig(Open207Z_SPIx_MOSI_GPIO_PORT, Open207Z_SPIx_MOSI_SOURCE, Open207Z_SPIx_MOSI_AF);
GPIO_InitStructure.GPIO_Pin = Open207Z_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(Open207Z_SPIx_SCK_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open207Z_SPIx_MISO_PIN;
GPIO_Init(Open207Z_SPIx_MISO_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open207Z_SPIx_MOSI_PIN;
GPIO_Init(Open207Z_SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure);
SPI_I2S_DeInit(Open207Z_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(Open207Z_SPIx, &SPI_InitStruct);
SPI_Cmd(Open207Z_SPIx, ENABLE);
追问
能给个QQ吗
追答
305514512
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询