本帖最后由 tgwfcc 于 2014-10-14 16:34 编辑
RT,程序为:
#define NRF_SCK3_L GPIO_ResetBits(GPIOB,GPIO_Pin_3)
#define NRF_SCK3_H GPIO_SetBits(GPIOB,GPIO_Pin_3)
#define NRF_MOSI3_H GPIO_SetBits(GPIOB,GPIO_Pin_5)
#define NRF_MOSI3_L GPIO_ResetBits(GPIOB,GPIO_Pin_5)
#define NRF_MISO3 GPIOB->IDR&0x0010 //PB4 读取PB4端口的状态
u8 SPI3_WR(u8 byte)
{
u8 k,receivedata;
for(k=0;k<8;k++)
{
NRF_SCK3_L; //SCK拉低
receivedata<<=1;
if(byte&0x80)
NRF_MOSI3_H; //写入1,MOSI为1
else
NRF_MOSI3_L; //写入0,MOSI为0
delay_us(1);
NRF_SCK3_H; //SCK拉高
byte<<=1;
if(NRF_MISO3) //读取MISO的值
receivedata |= 0x01;
else
receivedata &= 0xfe;
NRF_SCK3_L;
}
NRF_SCK3_L;
NRF_MOSI3_L;
return receivedata;
}
请大家帮我看看对不对,对时序图理解的不深,谢谢!
|