STM32F0xx_StdPeriph_Lib_EEPROM24LC16读写的BUG

2019-07-14 16:08发布

STM32F0的标准库的 uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)                            uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
函数貌似有个BUG  其实也不一定说是BUG,至少是不方便,迷惑使用着吧,因为调用者不会老盯住sEEAddress去切换扇区啊
就是写24LC16时地址0X100以前的数据可以读写
0X100以上的数据又把0X100以内的空间覆盖了
有人遇到过吗?
怎么解决的?

已经解决:

一,调用该函数之前改变sEEAddress
//#define sEE_HW_ADDRESS     0xA0   /* E2 = 0 */
// /*#define sEE_HW_ADDRESS     0xA2*/ /* E2 = 0 */  
// /*#define sEE_HW_ADDRESS     0xA4*/ /* E2 = 0 */
// /*#define sEE_HW_ADDRESS     0xA6*/ /* E2 = 0 */
// /*#define sEE_HW_ADDRESS     0xA8*/ /* E2 = 0 *//
// /*#define sEE_HW_ADDRESS     0xAA*/ /* E2 = 0 *//
// /*#define sEE_HW_ADDRESS     0xAC*/ /* E2 = 0 *///
/*#define sEE_HW_ADDRESS     0xAE*/ /* E2 = 0 */  /* Get number of reload cycles */


二,函数内部改变sEEAddress
uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
{  
  uint32_t NumbOfSingle = 0, Count = 0, DataNum = 0, StartCom = 0;
  //还是这么改好:

        sEEAddress =0x00a0;        
        sEEAddress +=(ReadAddr>>7)&0x000e;///////////////////20160811
...
}

uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
{   
  uint32_t DataNum = 0;
  sEE_WRITEALLOW();
    //sEEAddress要改变 ,或者在调用该函数之前改变
   //还是这么改好:
      sEEAddress =0x00a0;
        sEEAddress +=(WriteAddr>>7)&0x000e;///////////////////20160811
        

//        num=4;
//        test2[0] =0x10;
//        test2[1] =0x20;
//        test2[2] =0x30;
//        test2[3] =0x40;
//        test2[4] =0x50;
//        test2[5] =0x60;   
//        sEE_WriteBuffer(test2, 0x0, 4);
//        test2[0] =0x11;
//        test2[1] =0x22;
//        test2[2] =0x33;
//        test2[3] =0x44;
//        test2[4] =0x55;
//        test2[5] =0x66;
//        sEE_WriteBuffer(test2, 0x100, 4);
////        sEE_ReadBuffer(&test[0], 0x100,&num);
////        
////        sEE_ReadBuffer(&test[0], 0x0,&num);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。