硬件和软件都试过了,串口出来的数据都是一样,有问题.用的代码都是网上的 // 连续写N个字节 bool I2C2_Write_NByte(uint8_t SlaveAddress, uint8_t REG_Address, uint8_t* buf, uint16_t len) { uint16_t i; if(!I2C2_Start())return false; I2C2_Send_Byte(SlaveAddress); //发送设备地址+写信号 if(!I2C2_Wait_Ack()){I2C2_Stop(); return false;} I2C2_Send_Byte(REG_Address); if(!I2C2_Wait_Ack()){I2C2_Stop(); return false;} for(i=0; i<len; i++) { I2C2_Send_Byte(buf[i]); if(i<len-1) { if(!I2C2_Wait_Ack()){I2C2_Stop(); return false;} } } I2C2_Stop(); return true; } // 连续读N个字节 bool I2C2_Read_NByte(uint8_t SlaveAddress, uint8_t REG_Address, uint8_t* buf, uint16_t len) { uint16_t i; if(!I2C2_Start())return false; I2C2_Send_Byte(SlaveAddress); //发送设备地址+写信号 if(!I2C2_Wait_Ack()){I2C2_Stop(); return false;} I2C2_Send_Byte(REG_Address); if(!I2C2_Wait_Ack()){I2C2_Stop(); return false;} if(!I2C2_Start())return false; I2C2_Send_Byte(SlaveAddress | 1); // 读操作 if(!I2C2_Wait_Ack()){I2C2_Stop(); return false;} for(i=0; i<len; i++) { buf[i] = I2C2_Read_Byte(); if(i<len-1) { I2C2_Ack(); } } I2C2_NAck(); I2C2_Stop(); return true; } |
你先了解一下page size
然后写完一个page要等10ms, 才能再写