📄 5502_eeprom.c
字号:
/******************************************************************************/
/* Copyright 2004 by SEED Electronic Technology LTD. */
/* All rights reserved. SEED Electronic Technology LTD. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/* */
/******************************************************************************/
/*----------------------------------------------------------------------------*/
/* DESCRIPTION: */
/* */
/* This is an example of writting and reading E2PROM of DEC_5502 */
/*----------------------------------------------------------------------------*/
/* MODULE NAME... I2C and E2PROM */
/* FILENAME...... 5502_EEPROM.c */
/* DATE CREATED.. Mon 7/20/2004 */
/* COMPONENT..... */
/* PREREQUISITS.. */
/*----------------------------------------------------------------------------*/
#include <csl.h>
#include <csl_pll.h>
#include <csl_i2c.h>
#include <stdio.h>
#include "E2PROM_Function.h"
#undef E2PROM_ADDR // Define slave I2C device address
#define E2PROM_ADDR 0x50
/*------------------------------------------------------------------------------------*/
//
// Config I2C: Use I2C to interface E2PROM
//
/*------------------------------------------------------------------------------------*/
I2C_Setup Setup = {
0, // 7 bit address mode
0x0000, // own address
60, // clkout value (Mhz)
400, // a number between 10 and 400
0, // 8 bits/byte to be received or transmitted
0, // DLB mode off
0 // FREE mode off,如果采用7位或10位的寻址模式,必须关闭自由模式
};
// 定义写入8个字,合16个字节
#define DATALEN 0x08
/* Take two bytes addressing mode */
Uint16 SourData[DATALEN];
Uint16 DestData[DATALEN*2];
Uint16 DumyWrite[2] = {0,0};
/*------------------------------------------------------------------------------------*/
//
// FUNCTION: MAIN
//
/*------------------------------------------------------------------------------------*/
void main(void)
{
Uint16 i,Return;
Uint16 StartAdd = 0;
Uint16 Errcount = 0;
// Initialize CSL library - This is REQUIRED !!!
CSL_init();
// The main frequency of system is 240MHz
PLL_setFreq(1, 0xC, 0, 1, 3, 3, 0);
// Initialize I2C, Using parameters in MyI2c_Config structure
MyI2C_setup(&Setup);
for(i=0;i<DATALEN;i++)
{
DestData[2*i]=0;
DestData[2*i+1]=0;
SourData[i] = (2*i<<8)+2*i+1;
}
StartAdd = 0;
/*-------------- write---------------------------------------*/
for(i=0; i<DATALEN; i++)
{
Return = MyI2C_WriteSigWord( StartAdd, SourData[i], 1, E2PROM_ADDR, 1, 30000);
while(Return!=0);
StartAdd += 2;
}
/*-------------- read ---------------------------------------*/
// Perform dumy write operation
MyI2C_Write( DumyWrite, //pointer to data array
2, //length of data to be transmitted:
1, //master or slaver
E2PROM_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
MyI2C_Read( DestData,
DATALEN*2, // receives bytes of data
1, // in master receiver
E2PROM_ADDR, // Slave I2C address
1, // 该方式位必须正确设置,否则EEPROM会将数据线和时钟线拉低
30000, // with a timeout of 30000
0); // and check for bus busy on
/*----------------judge --------------------------------------------*/
Errcount = 0;
for(i=0; i<DATALEN; i++)
{
if(DestData[2*i] != (SourData[i]&0xFF00)>>8)
Errcount++;
if(DestData[2*i+1] != (SourData[i]&0x00FF))
Errcount++;
}
if(Errcount != 0)
printf("SEED_DEC5502 EEPROM 操作失败\n");
else
printf("SEED_DEC5502 EEPROM 操作成功\n");
}
/******************************************************************************/
// No more
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -