用SPI对一器件做读写操作,过程如下: #define SPI0_CS = (1<<24) PINSEL0 = 0x00005500; // 设置SPI管脚连接 PINSEL1 = 0x00000000;
IO1DIR = SPI0_CS; IO1SET = SPI0_CS; S0PCCR = 0x52; // 设置SPI时钟分频, 初始化SPI接口 S0PCR=0x38;//下降沿发送,上升沿接收
void SPI0_WR8(uint8 Addr,uint8 Dta) { IO1CLR=SPI0_CS; S0PDR = Addr|0x80; while( 0==(S0PSR&0x80) ); S0PDR = Dta; while( 0==(S0PSR&0x80) ); IO1SET|=SPI0_CS; } uint8 SPI0_RD8(uint8 Addr) { uint8 u8temp; IO1CLR=SPI0_CS; S0PDR = Addr; while( 0==(S0PSR&0x80) ); DelayNS(1); S0PDR = 0xff; while( 0==(S0PSR&0x80) ); u8temp=S0PDR; IO1SET|=SPI0_CS; return (u8temp); }
我先向器件的可读写寄存器中写入数据后再读怎么读不出来?
|