GPIO_InitTypeDef GPIOB_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
void RCC_Configura
tion(void)
{
RCC_DeInit();
SystemInit();
RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA
|RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO
, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1 , ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SPI1,ENABLE);
//SCK-PB3,MOSI-PB5
GPIOB_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_5;
GPIOB_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIOB_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&GPIOB_InitStructure);
//MISO-PB4
GPIOB_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIOB_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&GPIOB_InitStructure);
}
u8 SPI1_ReadWriteByte(u8 TxData)
{
SPI1->DR = TxData;
while (!(SPI1->SR & 0x01));
return (SPI1->DR);
}
void SPI_Configuration(void)
{
SPI_Cmd(SPI1, DISABLE);
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_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;//56M/128=437.5K
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
SPI1_ReadWriteByte(0xff);
}
在SPI1_ReadWriteByte(0xff);处设置断点,单步运行,发现SPI1->DR 寄存器数据一直显示为0x00.请各位技术大牛帮忙看看
你这分得的真爽。
一周热门 更多>