配置SPI1时能够正常的读取flash信息,但是用SPI2的时候连SPI中时钟都没有,但是再三确定了配置函数不知道哪里出错
/********************************* COPYRIGHT 2014 -------- ********* BEGIN OF FILE ********************************/
/**********************************************************************
* file : spi2.c
* author : --
* version : --
* date : 2018-12-29
* brief : spi1 program body
* Description : --
**********************************************************************/
/* Includes == 文件包含 --------------------------------------------*/
#include "spi2.h"
/* Private typedef == 私有类型 ----------------------------------*/
/* Private define == 私有定义 ----------------------------------*/
//-----------------------------------------//
#define sEE_SPI2 SPI2
#define sEE_SPI2_CLK RCC_APB1Periph_SPI2
#define sEE_SPI2_SCK_PIN GPIO_Pin_13 /* PB.13 */
#define sEE_SPI2_SCK_GPIO_PORT GPIOB /* GPIOB */
#define sEE_SPI2_SCK_GPIO_CLK RCC_AHBPeriph_GPIOB
#define sEE_SPI2_SCK_SOURCE GPIO_PinSource13
#define sEE_SPI2_SCK_AF GPIO_AF_SPI2
#define sEE_SPI2_MISO_PIN GPIO_Pin_14 /* PB.14 */
#define sEE_SPI2_MISO_GPIO_PORT GPIOB /* GPIOB */
#define sEE_SPI2_MISO_GPIO_CLK RCC_AHBPeriph_GPIOB
#define sEE_SPI2_MISO_SOURCE GPIO_PinSource14
#define sEE_SPI2_MISO_AF GPIO_AF_SPI2
#define sEE_SPI2_MOSI_PIN GPIO_Pin_15 /* PB.15 */
#define sEE_SPI2_MOSI_GPIO_PORT GPIOA /* GPIOB */
#define sEE_SPI2_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOB
#define sEE_SPI2_MOSI_SOURCE GPIO_PinSource15
#define sEE_SPI2_MOSI_AF GPIO_AF_SPI2
/* Private macro == 私有宏 ------------------------------------*/
/* Private variables == 私有变量 ----------------------------------*/
/* Private functions == 私有函数定义 ------------------------------*/
/**********************************************************************
* @Fuctionname : None
* @Brief : None
* @Input : None
* @Output : None
* @Return : None
* @Remark : None
**********************************************************************/
void SPI2_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
/*!< sEE_CS_GPIO, sEE_MOSI_GPIO, sEE_MISO_GPIO and sEE_SCK_GPIO
Periph clock enable */
RCC_AHBPeriphClockCmd(sEE_SPI2_MOSI_GPIO_CLK | sEE_SPI2_MISO_GPIO_CLK | sEE_SPI2_SCK_GPIO_CLK , ENABLE);
/*!< sEE Periph clock enable */
RCC_APB1PeriphClockCmd(sEE_SPI2_CLK, ENABLE);
/*!< Configure sEE pins: SCK */
GPIO_InitStructure.GPIO_Pin = sEE_SPI2_SCK_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(sEE_SPI2_SCK_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sEE_SPI pins: MISO */
GPIO_InitStructure.GPIO_Pin = sEE_SPI2_MISO_PIN;
GPIO_Init(sEE_SPI2_MISO_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sEE_SPI pins: MOSI */
GPIO_InitStructure.GPIO_Pin = sEE_SPI2_MOSI_PIN;
GPIO_Init(sEE_SPI2_MOSI_GPIO_PORT, &GPIO_InitStructure);
/* Connect PXx to sEE_SPI_SCK */
GPIO_PinAFConfig(sEE_SPI2_SCK_GPIO_PORT, sEE_SPI2_SCK_SOURCE, sEE_SPI2_SCK_AF);
/* Connect PXx to sEE_SPI_MISO */
GPIO_PinAFConfig(sEE_SPI2_MISO_GPIO_PORT, sEE_SPI2_MISO_SOURCE, sEE_SPI2_MISO_AF);
/* Connect PXx to sEE_SPI_MOSI */
GPIO_PinAFConfig(sEE_SPI2_MOSI_GPIO_PORT, sEE_SPI2_MOSI_SOURCE, sEE_SPI2_MOSI_AF);
/*!< sEE SPI Config */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//SPI_NSS_Hard;//SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(sEE_SPI2, &SPI_InitStructure);
SPI_Cmd(sEE_SPI2, ENABLE); /*!< sEE_SPI enable */
}
/**********************************************************************
* @Fuctionname : None
* @Brief : None
* @Input : None
* @Output : None
* @Return : None
* @Remark : None
**********************************************************************/
u8 SPI2_ReadWriteByte(u8 dat)
{
/*!< Loop while DR register in not empty */
while (SPI_I2S_GetFlagStatus(sEE_SPI2, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI peripheral */
SPI_SendData(sEE_SPI2, dat);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(sEE_SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/*!< Return the byte read from the SPI bus */
return (uint8_t)SPI_ReceiveData(sEE_SPI2);
}
/********************************* COPYRIGHT 2014 -------- ********* END OF FILE **********************************/
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
发帖的时候,自动设为黑背景了,重新发了,能请赐教一下吗
一周热门 更多>