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)
碰到这个问题: 写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 */
现在改进内部函数如下,方便和我一样迷惑的菜鸟
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;
。。。
。。。
}
uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
{
uint32_t DataNum = 0;
sEE_WRITEALLOW();
//这里加
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);
这次还有个新发现,标准库1.0和1.5好像蛮接近,老程序放到新库里编译可以通过。
|