⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeprom.c

📁 Discription: This multi-master driver provides the software interface to the I2C Bus hardware of th
💻 C
字号:
		 /*******************************************************************
 *
 *    DESCRIPTION:	eeprom.c - module for reading and writing EEPROM
 *
 *    AUTHOR:			 O. Kessel-Deynet
 *
 *      Lightmaze AG    
 *
 *******************************************************************/

/** include files **/
#include "Types/Sfr.h"
#include "i2c.h"
#include <string.h>
#include "Rtos.h"

extern byte wrtNoStopCond;

/** public functions **/

bool writeEEProm(byte adr, byte len, byte* pdata, byte devAdr)
{
	bool back = true;
	byte bcount, blen, arrayPoint;
	byte *bpdata;
	byte writeBuffer[17];
// EEPROM is flashed in pages of max. 16 bytes in one "row", i.e. with the
// same four most significant bits in the address.
	
	arrayPoint = 0;
	while(len > 0) {
		bcount = 0x10 - ((adr + arrayPoint) & 0x0f);
		blen = (bcount < len) ? bcount : len;
		bpdata = &(pdata[arrayPoint]);
		writeBuffer[0] = adr + arrayPoint;
		memcpy(&(writeBuffer[1]), bpdata, blen);
		if( masterWriteI2C( blen+1, writeBuffer, devAdr)) {
			back = false;
			break;
		}

		OS_Delay(10); // this delay is the duration of the internal write cycle of the EEPROM
		arrayPoint += blen;
		len -= blen;
	}
	return back;
}

bool readEEProm(byte adr, byte len, byte *pdata, byte devAdr)
{

// this flag determines that no stop condition should be sent after the dummy write.
// It is automatically cleared by the I2C driver after usage.
	bool back = true;
	wrtNoStopCond = 1;

	if( masterWriteI2C( 1, &adr, devAdr ))
	{
		back = false;
	} else {
		masterReadI2C(len, pdata, devAdr);
	}
	return back;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -