我寫入的DataFlash的驅(qū)動程序如下
/* ?*?MyDataFlash.c ?* ?*??Created?on:?Aug?25,?2022 ?*??????Author:?Lee ?*/ #include?"MyDataFlash.h" #include?"config.h" #include?"multiCentral.h" volatile?uint8_t?MacAddr_Update_Flag=0; uint8_t?MyDataFlash_Check(void) { ????u8?temp; ????EEPROM_READ(FIRST_POWON_ADDR,&temp,?1);//避免每次開機都寫DataFlash ????EEPROM_READ(SLAVE1_STARTADDR,&PeerAddrDef[0],?6); ????EEPROM_READ(SLAVE2_STARTADDR,&PeerAddrDef[1],?6); ????PRINT("Device?%d?-?Addr?%02x?%02x?%02x?%02x?%02x?%02x?\n",?0, ????????????PeerAddrDef[0].peerAddr[0], ????????????PeerAddrDef[0].peerAddr[1], ????????????PeerAddrDef[0].peerAddr[2], ????????????PeerAddrDef[0].peerAddr[3], ????????????PeerAddrDef[0].peerAddr[4], ????????????PeerAddrDef[0].peerAddr[5]); ????PRINT("Device?%d?-?Addr?%02x?%02x?%02x?%02x?%02x?%02x?\n",?1, ????????????PeerAddrDef[1].peerAddr[0], ????????????PeerAddrDef[1].peerAddr[1], ????????????PeerAddrDef[1].peerAddr[2], ????????????PeerAddrDef[1].peerAddr[3], ????????????PeerAddrDef[1].peerAddr[4], ????????????PeerAddrDef[1].peerAddr[5]); ????if(temp==FIRST_POWON_VALU)return?0; ????else//排除第一次初始化的情況 ????{ ????????memcpy(&PeerAddrDef[0],"\x99\x59\x9C\x4C\x17\x20",6); ????????EEPROM_WRITE(SLAVE1_STARTADDR,?&PeerAddrDef[0],?6); ????????memcpy(&PeerAddrDef[1],"\x59\x59\x9C\x4C\x17\x20",6); ????????EEPROM_WRITE(SLAVE2_STARTADDR,?&PeerAddrDef[1],?6); ????????temp=FIRST_POWON_VALU; ????????EEPROM_WRITE(FIRST_POWON_ADDR,?&temp,?1); ????????EEPROM_READ(FIRST_POWON_ADDR,?&temp,?1); ????????if(temp==FIRST_POWON_VALU)return?0; ????} ????return?1; } void?MyDataFlash_SaveMAC(?uint8_t*?Addr1,uint8_t*?Addr2) { ????uint8_t?d[12]={0}; ????PRINT("Device?%d?-?Addr?%02x?%02x?%02x?%02x?%02x?%02x?\n",?0, ????????????Addr1[0], ????????????Addr1[1], ????????????Addr1[2], ????????????Addr1[3], ????????????Addr1[4], ????????????Addr1[5]); ????PRINT("Device?%d?-?Addr?%02x?%02x?%02x?%02x?%02x?%02x?\n",?1, ????????????Addr2[0], ????????????Addr2[1], ????????????Addr2[2], ????????????Addr2[3], ????????????Addr2[4], ????????????Addr2[5]); ????EEPROM_WRITE(SLAVE1_STARTADDR,?Addr1,?6); ????EEPROM_WRITE(SLAVE2_STARTADDR,?Addr2,?6); }
另有頭文件如下
/* ?*?MyDataFlash.h ?* ?*??Created?on:?Aug?25,?2022 ?*??????Author:?Lee ?*/ #ifndef?_MYDATAFLASH_H_ #define?_MYDATAFLASH_H_ #include?"CH58x_common.h" #define?FIRST_POWON_ADDR????0xFF//第一次開機校驗的值存儲的地址 #define?FIRST_POWON_VALU????0xA5//第一次開機校驗的值 #define?SLAVE1_STARTADDR????0x00//從機1的mac在dataflash中的首地址 #define?SLAVE2_STARTADDR????SLAVE1_STARTADDR+6//從機2的mac在dataflash中的首地址 extern?volatile?uint8_t?MacAddr_Update_Flag; extern?uint8_t?MyDataFlash_Check(void); extern?void?MyDataFlash_SaveMAC(?uint8_t*?Addr1,uint8_t*?Addr2); #endif?/*?_MYDATAFLASH_H_?*/
現(xiàn)在發(fā)現(xiàn)MyDataFlash_SaveMAC這個函數(shù)寫入的值如下
Device 1 - Addr 99 59 9c 4c 17 20?
Device 2 - Addr 59 59 9c 4c 17 20?
然后開機通過這個
MyDataFlash_Check
函數(shù)讀出:
Device 0 - Addr 59 19 9c 4c 17 20?
Device 1 - Addr 89 51 9c 4c 17 20?
發(fā)現(xiàn)前面兩個字節(jié)變掉了
熱門產(chǎn)品 :
CH182: 以太網(wǎng)PHY收發(fā)器芯片