This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] EK-TM4C123GXL:I'm 正在尝试生成可从外部 EEPROM 读取数据和向外部 EEPROM 写入数据的函数

Guru**** 1135610 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1207126/ek-tm4c123gxl-i-m-trying-to-make-functions-that-read-and-write-data-to-external-eeprom

器件型号:EK-TM4C123GXL

我创建了函数、但我不知道代码为什么不起作用。 我的 I2C 协议是否错误? 我的 EEPROM 为24LC43A


void I2C_setup(){
   RCGCGPIO |= 0x8;//端口 E 时钟使能
   RCGCI2C |= 0x8;//I2C 模块3使能
   GPIODEN_PORTD = 0x3;//为端口 D0和 D1 => 00000011启用数字功能
   GPIOAFSEL_PORTD |= 0x3;// D0和 D1有一个替代函数
   GPIOPCTL_PORTD |= 0x33;//针对 D0和 D1 (即 SCL 和 SDA)使用函数3
   GPIOODR_PORTD |= 0x2;//DRAIN 表示 D1 00000010
   I2CMCR_3 = 0x10;//这是主机
   I2C_SET_SCL_PEiiod (0.0001);
}

void I2C_SET_SCL_peiiod (double SCL_period){
   I2CMTPR_3 = SCL_PERIOD * 800000 + 1;
}

void I2Ceprom_byte_write (char data、int address)

   char upper_address =(unsigned) address >> 8;
   char lower_address =(unsigned) address & 0xff;
   //发送启动条件
   I2CMSA_3 = 0xA0;//1010 000 0发送
   I2CMCS_3 = 0x3;//00011生成 START 位和 I2C 使能
   I2C_EEPROM_WAIT ();


   I2CMDR_3 = UP_ADDRESS;//发送地址(1/2)
   I2CMCS_3 = 0x1;
   I2C_EEPROM_WAIT ();


   I2CMDR_3 = LOWER_ADDRESS;//发送地址(2/2)
   I2CMCS_3 = 0x1;
   I2C_EEPROM_WAIT ();

   I2CMDR_3 =数据;
   I2CMCS_3 = 0x5;//生成 STOP
   I2C_EEPROM_WAIT ();
   I2C_EEPROM_BUS_WAIT ();
}

int I2Ceprom_byte_read (int 地址)

   char upper_address =(unsigned) address >> 8;
   char lower_address =(unsigned) address & 0xff;
   Int 数据;

   I2CMSA_3 = 0xA0;
   I2CMCS_3 = 0x3;
   I2C_EEPROM_WAIT ();

   I2CMDR_3 = UP_ADDRESS;
   I2CMCS_3 = 0x1;
   I2C_EEPROM_WAIT ();


   I2CMDR_3 = LOWER_ADDRESS;
   I2CMCS_3 = 0x1;
   I2C_EEPROM_WAIT ();


   I2CMSA_3 = 0xA1;
   I2CMCS_3 = 7;
   I2C_EEPROM_WAIT ();
   I2C_EEPROM_BUS_WAIT ();
   数据= I2CMDR_3;
   返回数据;
}

void I2C_EEPROM_WAIT (){
   while (I2CMCS_3和0x1);
}

void I2C_EEPROM_BUS_WAIT (){
   while (I2CMCS_3和0x40);
}