新手上路
- 积分
- 45
- 金钱
- 45
- 注册时间
- 2014-1-15
- 在线时间
- 0 小时
|
使用PB6、7、8、9模拟SPI,初始化程序和读写程序如下,但读取器件ID一直是FF,找不到原因,求帮助。芯片为W25Q32.
void SPIx_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; // F_CS使能脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //F_SO--> B.7
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //F_SCLK--> B.8
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //F_SI--> B.9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
u8 Soft_SPI_ReadWrite_Byte(u8 send_data)
{
u8 i,j;
for(i = 0;i < 8;i++)
{
if(send_data & 0x80) F_SI = 1;
else F_SI = 0;
send_data <<= 1; //
F_SCLK = 0;
for(j=0;j<50;j++)
;
F_SCLK = 1; //
if(F_SO) send_data |= 0x01; //
}
F_SCLK = 0;
return send_data;
}
|
|