0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

如何使用MAX2990 I²C接口编写工业标准EEPROM

星星科技指导员 来源:ADI 作者:ADI 2023-01-12 09:48 次阅读

文章和固件代码示例介绍了如何使用MAX2990电力线通信调制解调器上的IC接口与外部EEPROM 24C04接口。

介绍

本应用笔记和固件代码示例描述了MAX2990电力线通信调制解调器上的IC接口如何与外部EEPROM 24C04接口。IC总线由MAX2990(主机)控制,24C04 EEPROM由从机控制。下面的示意图显示了此示例中使用的硬件配置。

pYYBAGO_ZwuANZftAAAYjLb2-sA586.gif?imgver=1

固件说明

IC接口初始化

每当使能IC模块时,SCL和SDA必须配置为漏极开路。此配置是IC通信正常运行所必需的。由于IC是GPIO端口的替代功能,固件必须确保在初始化期间禁用SCL和SDA输入上的上拉(通过将零写入该端口控制器输出位)。

该示例具有 250kHz 时钟频率。首先,需要在MAX2990中设置IC接口,如下所示:

PO1_bit.Bit2 = 0; 		// Disables the GPIO function of the
PO1_bit.Bit3 = 0; 		// I2C pins

I2CCN_bit.I2CEN = 0; 	// Makes sure that I2C is disabled
			// to allow the changing of the I2C settings

I2CCN_bit.I2CMST = 1; 		// Sets the I2C engine to master mode
I2CCN_bit.I2CEA = 0; 		// 7-bit address mode
I2CCK_bit.I2CCKL = 0x40; 	// 2µs CLK-low, to define I2C frequency
I2CCK_bit.I2CCKH = 0x40; 	// 2µs CLK-high, to define I2C frequency

I2CTO = 200; 		// I2C_TIMEOUT
I2CST = 0x400; 		// Resets I2C status register

I2CCN_bit.I2CEN = 1; 		// Enables the I2C engine

写入模式

要写入 24C04 EEPROM,必须通过 IC 接口写入以下字节:

IC EEPROM 的地址(在本例中0xA0)

EEPROM 中存储器位置的地址

数据字节(地址将自动增加)

在此示例中,我们尝试从位置0x00开始将以下字节写入EEPROM:0x12,0x34,0x56,0x78和0x90。

i2c_init_write(); 	// Sets the MAX2990 I2C Engine into write mode
i2c_write(0x50); 	// 24C04 write (adr = 0b1010 000 0) = 0xA0
			// The MAX2990 I2C engine shifts the I2C address by
			// 1 bit, because it will generate the R/W bit
			// automatically

i2c_write(0x00); 	// word address location
i2c_write(0x12); 	// data1
i2c_write(0x34); 	// data2
i2c_write(0x56); 	// data3
i2c_write(0x78); 	// data4
i2c_write(0x90); 	// data5
I2C_STOP; 		// Sends I2C stop-condition

poYBAGO_Zw2AcV04AAArexTx28c660.gif?imgver=1

阅读模式

为了回读数据,我们从EEPROM写入。重要的是,我们要给 24C04 足够的时间来编写。这通常需要在“停止条件”后的几毫秒内。请查阅IC的数据手册,确保使用正确的时序。

i2c_init_write(); 	// Sets the MAX2990 I2C engine into write mode
i2c_write(0x50); 	// 24C04 write (adr = 0b1010 000 0) = 0xA0
			// The MAX2990 I2C engine shifts the I2C address by
			// 1 bit, because it will generate the R/W bit
			// automatically

i2c_write(0x00); 	// word address location

i2c_init_read(); 	// Sets the MAX2990 I2C engine into read mode

i2c_write(0x50); 	// 24C04 read (adr = 0b1010 000 1) = 0xA1
			// The MAX2990 I2C engine shifts the I2C address by
			// 1 bit, because it will generate the R/W bit
			// automatically

unsigned char data[5]; 		// Array to store the received data
i2c_read(data[0]); 		// Reads 1 byte from I2C and writes it to the array
i2c_read(data[1]); 		// Reads 1 byte from I2C and writes it to the array
i2c_read(data[2]); 		// Reads 1 byte from I2C and writes it to the array
i2c_read(data[3]); 		// Reads 1 byte from I2C and writes it to the array
i2c_read(data[4]); 		// Reads 1 byte from I2C and writes it to the array
I2C_STOP; 			// Sends I2C stop-condition

现在我们检查以下用于读取和写入EEPROM的函数。

i2c_init_write(void)
i2c_init_read(void)
i2c_write(UINT8 data)
i2c_read(UINT8 *data)

pYYBAGO_ZxCAErhmAABO0Okhm0E415.gif?imgver=1

void i2c_init_write(void)
{
I2CCN_bit.I2CMODE = 0; 	// I2C transmit mode
I2CCN_bit.I2CACK = 1; 	// Creates I2C NACK so that slave can create ACK
I2C_START; 		// Generates I2C START condition
while( I2CCN_bit.I2CSTART == 1 ); 	// Waits until the START condition
					// was put to the I2C bus
I2CST_bit.I2CSRI = 0; 			// Resets the I2C interrupt flag
}

int i2c_init_read(void)
{
I2CCN_bit.I2CMODE = 1; 	// I2C read-mode
I2CCN_bit.I2CACK = 0; 	// Creates I2C ACK after receive
I2C_START; 		// Generates I2C START condition

while( I2CCN_bit.I2CSTART == 1 ); 	// Waits until the START condition
I2CST_bit.I2CSRI = 0; 			// Resets the I2C interrupt flag
}

void i2c_write(UINT8 data)
{
I2CBUF = data; 				// Puts the data on the I2C bus
while( I2CST_bit.I2CTXI == 0 ); 	// Waits for transfer complete
I2CST_bit.I2CTXI = 0; 			// Resets the I2C transmit complete
					// interrupt flag
}

void i2c_read(UINT8 *data)
{
I2CBUF = 0xff; 		// Puts "all ones" on the I2C bus so that slave can pull
			// the bus down to generate zeros

while( !I2CST_bit.I2CRXI ); 		// Waits for receive complete
I2CST_bit.I2CRXI=0; 			// Resets the I2C receive complete
					// interrupt flag

*data = I2CBUF; 			// Writes the data to the pointer
}

审核编辑:郭婷

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 调制解调器
    +关注

    关注

    3

    文章

    821

    浏览量

    38388
  • 总线
    +关注

    关注

    10

    文章

    2706

    浏览量

    87222
  • 代码
    +关注

    关注

    30

    文章

    4556

    浏览量

    66782
收藏 人收藏

    评论

    相关推荐

    USB总线转I2C总线接口芯片

    )<br/>/MAX1239(12bitADC);I2C接口数模转换DAC芯片DAC5574(8bitDAC)/DAC6573(10bitDAC)/DAC8571&
    发表于 12-16 10:39

    I2C总线接口EEPROM应用笔记

    本帖最后由 eehome 于 2013-1-5 09:47 编辑 I2C总线接口EEPROM应用笔记
    发表于 08-20 13:27

    PSoC 4与EEPROM接口

    嗨,大家好,有没有人将PSoC 4200—L与EEPROM接口?对于I2C或SPI,我有2种类型的EEPROM在BARADS上用于不同的存储功能。我曾尝试使用SBC模式,但看起来不同于
    发表于 11-26 15:43

    EEPROM的3个常规接口

    EEPROM的常规接口有3个分别是Microwire和SPI与I2C。这些接口各自具有技术特点。请选择符合客户需求的接口。【
    发表于 03-15 06:20

    怎么将I2C RTC和EEPROM与18F420接口

    我正在尝试将I2C RTC(MCP7940N)和EEPROM(24LC32 A)与18F420接口。我以前在18F45 2上做了一个实验室(是的,我知道它已经过时了,它是我必须学习的DEV板
    发表于 04-16 06:55

    如何用dsp标准I2C接口接ADS1110?

    想用dsp的官方“I2C 存储eeprom”例程改写一个I2C 通信程序,硬件上是:用dsp的标准I2C
    发表于 10-24 08:04

    四路I2C电压电流和温度监控器LTC2990

    LTC2990的典型应用用于监控系统温度,电压和电流。通过I2C串行接口,该器件可配置为测量内部温度,远程温度,远程电压,远程电流和内部VCC的多种组合
    发表于 04-08 08:11

    电源监视电路LTC2990电子资料

    概述:LTC2990采用10引脚MSOP封装。是一款面向 3V 和 5V 系统的 I2C 温度和电压监视器。该器件整合了一个 14 位 ADC、一个10ppm/C 电压基准和 I2C
    发表于 04-09 07:03

    i2c总线用户接口进行访问EEPROM如何才能实现呢

    i2c总线用户接口进行访问EEPROM如何才能实现呢?
    发表于 03-07 07:53

    如何在RK2206开发板上使用I2C控制EEPROM读写呢

    程序设计API分析eeprom_init()unsigned int eeprom_init();描述:EEPROM初始化,包括i2c初始化。参数:无返回值:0为成功,反之失败
    发表于 08-11 16:47

    CH365使用外部ID可以通过I2C接口扩展EEPROM实现吗?

    开发CH365板卡,想要使用外部ID,看例程貌似是需要通过本地总线扩展ROM才能实现,想请问一下,这是唯一的方法吗,可以利用I2C接口连接EEPROM(24C02)实现吗
    发表于 10-11 07:02

    MAX2990 pdf

    The MAX2990 power line communication (PLC) base- band modem delivers a cost-effective
    发表于 06-30 13:41 87次下载

    MAX2990 Integrated Power-Line

    This programming manual describes the chip architecture and programming capabilities of the MAX2990
    发表于 07-24 12:09 16次下载

    如何通过MAX2990 I2C接口标准EEPROM (24

      引言   本文介绍了如何通过MAX2990电力线通信调制解调器的
    发表于 10-22 11:32 1291次阅读
    如何通过<b class='flag-5'>MAX2990</b> I2C<b class='flag-5'>接口</b>向<b class='flag-5'>标准</b><b class='flag-5'>EEPROM</b> (24

    如何使用 MAX2990 I²C 接口编写工业标准 EEPROM (24C04)

    发表于 11-17 12:42 0次下载
    如何使用 <b class='flag-5'>MAX2990</b> I²C <b class='flag-5'>接口</b><b class='flag-5'>编写</b><b class='flag-5'>工业</b><b class='flag-5'>标准</b> <b class='flag-5'>EEPROM</b> (24C04)