为什么我的AT25256读写不正确,请帮忙看下 ////////////////////////////////////// void SPI_WREN(void) { SPI_CS=0; //选中AT25256 Tx_SPI(0x06); //写允许,只有操作码 SPI_CS=1; } /////////////////////////////////// void SPI_WRDI(void) { SPI_CS=0; //选中AT25256 Tx_SPI(0x04); //写禁止,只有操作码 SPI_CS=1; } //////////////////////////////////// uchar SPI_RDSR(void) { uchar read_state; //读状态寄存器,操作码+一个字节 SPI_CS=0; //选中AT25256 Tx_SPI(0x05); read_state=Rx_SPI(); SPI_CS=1; return read_state; } //////////////////////////////////////////// void SPI_WRITE(uchar address_H,uchar address_L,write_data) { uchar state; state=1; SPI_WREN(); //开启写 SPI_CS=0; //选中AT25256 Tx_SPI(0x02); //写的指令 Tx_SPI(address_H); Tx_SPI(address_L); Tx_SPI(write_data); SPI_CS=1; while(state)//写等待 {state=SPI_RDSR();} SPI_WRDI(); //禁止写 } ///////////////////////////////// uchar SPI_READ(uchar address_H,uchar address_L) { uchar Rx_data; //SPI_HOLD=1; SPI_CS=0; //选中AT25256 Tx_SPI(0x03); Tx_SPI(address_H); Tx_SPI(address_L); Rx_data=Rx_SPI(); SPI_CS=1; return Rx_data; } ////////////////////////////////////////// |