的spi配置sck只有4个半字节,造成数据不能收发,求解,下面是代码
void SPI_EEPROM_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;SPI_InitTypeDef SPI_InitStructure;RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
/*SPI3_MISO--PB4;´/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4 ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
/*SPI3_MOSI--PB5;¸/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5 ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
/*SPI3_SCK--PB3;/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3 ;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
SPI_EEPROM_CS_HIGH();
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_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI3,&SPI_InitStructure);
SPI_Cmd(SPI3,ENABLE);}
u8 SPI_EEPROM_SendByte(u8 byte)
{
while(SPI_I2S_GetFlagStatus(SPI3,SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI3,byte);
while(SPI_I2S_GetFlagStatus(SPI3,SPI_I2S_FLAG_RXNE) == RESET);
return SPI_I2S_ReceiveData(SPI3);
}
int main(void)
{
RCC_Configuration();
SPI_EEPROM_Init();
while(1)
{
SPI_EEPROM_CS_LOW();
SPI_EEPROM_SendByte(0x06);
SPI_EEPROM_CS_HIGH();
}}
-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>