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.

[参考译文] CC3220SF-LAUNCHXL:使用 TI 驱动器将24C02 I2C EEPROM 与 CC3220SF 连接

Guru**** 2536770 points
Other Parts Discussed in Thread: CC3220SF-LAUNCHXL, TMP116

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

https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/920285/cc3220sf-launchxl-interface-24c02-i2c-eeprom-with-cc3220sf-using-ti-drivers

器件型号:CC3220SF-LAUNCHXL
主题中讨论的其他器件: TMP116

您好!

我在 I2C 线路上使用 CC3220SF-LAUNCHXL LP 和24C02 EEPROM 时遇到了一个非常简单的问题。 我的任务是在 I2C EEPROM 的内部存储器0x00写入一个字节的数据 、然后将其读回并通过 UART 日志显示。 我浏览了资源浏览器中给出的 TMP116温度传感器示例,并修改了 i2ctmp.c 中的代码。 我在重新启动条件生成方面遇到问题、需要使用虚拟写入来设置 EEPROM (I2C)的内部地址。

我正在使用 ti/drivers/I2C.h 并且我正在使用 I2C_transfer ()函数从 EEPROM 发送和读取数据。 但写入操作和读取操作不成功。 代码如下所示、如有任何帮助、请予以帮助:

/*
=== i2ctmp116.c ===
*/
#include 
#include 
#include 

/*驱动程序头文件*/
#include 
#include 
#include 

/*驱动程序配置*/
#include "ti_drivers_config.h"

#define TASKSTACKSIZE 640

/*
===== tmp 寄存器======
*/

#define _24C64_REG 0x00;//对于 C64、最大寄存器 val 为0b0001111111111111 = 0x1fff
#define _24C64_ADDR 0x50;//在7位地址

静态 Display_Handle 显示之前附加0;

//
*=== mainThread ====
//
void * mainThread (void * arg0)
{
uint16_t 样本;
uint16_t 温度;
uint8_t txBuffer[3];
uint8_t rxBuffer[10];
I2C_Handle I2C;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;

/*调用驱动程序初始化函数*/
display_init();
GPIO_init();
I2C_init();

/*配置 LED 以及 TMP116_EN 引脚(如果适用)*/
GPIO_setConfig (CONFIG_GPIO_LED_0、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
#ifdef CONFIG_GPIO_TMP116_EN
GPIO_setConfig (CONFIG_GPIO_TMP116_EN、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
TMP116的/* 1.5ms 复位时间*/
睡眠(1);
#endif

/*打开主机显示屏以输出*/
Display = Display_open (Display_Type_UART、NULL);
if (display =NULL){
while (1);
}

/*打开用户 LED */
GPIO_WRITE (CONFIG_GPIO_LED_0、CONFIG_GPIO_LED_ON);
display_printf (display、0、0、"启动 i2c24C64示例\n");

/*创建 I2C 以供使用*/
I2C_Params_init (&i2cParams);
i2cParams.bitrate = I2C_100kHz;
I2C = I2C_open (CONFIG_I2C_TMP、&i2cParams);
if (i2c == NULL){
Display_printf (display、0、0、"Error Initializing I2C\n");
while (1);
}
否则{
display_printf (display、0、0、"I2C initialized!\n"\});
}

/*通用 I2C 事务设置*/
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.ReadCount = 0;

Display_printf (display、0、0、"使用数据0x32写入 EEPROM 的地址0x00");
TxBuffer[0]= 0x00;
txBuffer[1]='2';
i2cTransaction.slaveAddress =_24C64_ADDR;
if (!I2C_transfer (i2c、&i2cTransaction))
{
Display_printf (display、0、0、"错误。 未找到24C64从 EEPROM! NACK 错误");
}
display_printf (display、0、0、"Write successful");


/*睡眠1秒*/
睡眠(1);



/*
*读取地址集和读取数据
*
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.ReadCount = 10;

display_printf (display、0、0、"设置 EEPROM 的地址= 0x50");
TxBuffer[0]= 0x00;
txBuffer[1]= 0xA1;//读取 EEPROM 的 I2C 芯片地址

i2cTransaction.slaveAddress =_24C64_ADDR;
IF (I2C_transfer (i2c、&i2cTransaction))
{
Display_printf (display、0、0、"找到24C02从设备 EEPROM!");

对于(采样= 0;采样< 10;+sample)
{
温度= rxBuffer[采样];
display_printf (display、0、0、"value for read[%d]:%d -\r\n、sample、temperature);
}

}



I2C_Close (i2c);
display_printf (display、0、0、"I2C closed!");

返回(NULL);
} 

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

    您好!

    为了确保 I2C 线路与其他组件完全隔离、您是否移除了连接到温度传感器的 I2C 跳线?

    此外、我对您正在使用的 EEPROM 进行了快速搜索。 我看到这是一个5V 器件、而我们的 GPIO 最大可驱动3.3V 您是否使用逻辑电平转换器连接 EEPROM?

    假设您设置了正确的从器件地址、您的代码一览无误。

    Jesu

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

    您好、Jesu、

    感谢您的回复。 是的、我打开了板载到温度传感器和 Acc 传感器的跳线、并将它们连接到 EEPROM。  

    是的、该 EEPROM 是5V EEPROM、但在3V3级别工作非常顺利。 我在3V3线路上使用此芯片已近15年、它没有任何投诉。

    是的。 我使用的从器件地址看起来很好。 这是因为 EEPROM 的数据表显示了从器件地址。 为1010 A2 A1 A0 (其中 Ax 是现在连接到接地的硬接线地址线路)。 因此、在我的示例中、地址将为1010000、附加0会使我01010000 = 0x50。 对于读取操作、它直接作为数据发送、我将其设置为10100001 (对于读取情况、最后一位是 R/W'= 1)= 0xA1。

    我只是想知道,用于 TI RTOS 2.2的 I2C TI 驱动程序有一些特殊的功能用于重复的启动用例,或者它是否必须作为新的 I2C 事务数据流单独发送?

    再次感谢您的帮助!

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

    您好!

    我现在似乎已经找到了解决这一问题的办法。 我已经测试了对0x10到0x14之间相邻存储器位置连续5次写入的写入、写入值为0x01、0x02、0x03、0x04和0x05。 这是顺序写入。 然后、我将从相同的存储器位置读取数据、同时读取更多相邻的存储器位置、直到0x19。 如输出所示、从存储器位置0x10到0x14读取的输出是那些被写入的输出。 但是、将存储器区域从0x15重新存储到0x19中的值是新 EEPROM 中现有的未写入值0xff。 代码和输出如下所示:

    /*
    版权所有(c) 2018-2019、德州仪器(TI)公司
    *保留所有权利。
    *
    *
    只要
    符合以下条件*、允许以源代码和二进制形式重新分发和使用:
    *
    *源代码的重新分发必须保留上述版权
    声明*、此条件列表和以下免责声明。
    *
    ***二进制形式的再发行必须在
    
    *随发行提供的文档和/或其他材料中复制上述版权声明、本条件列表和以下免责声明。
    *
    ***未经
    
    事先书面许可、不得使用德州仪器公司的名称或*其贡献者的名称认可或推广从本软件衍生的产品*。
    *
    *本软件由版权所有者和贡献者"按原样"提供
    *、
    
    不承担任何明示或暗示的保证、包括但不限于*适销性和特定用途适用性的暗示保证*。 在任何情况下、版权所有者或
    *贡献者都不对任何直接、间接、偶然、特殊、
    *模范、 或相应的损害(包括但不限于
    *采购替代产品或服务;丧失使用、数据或利润;
    *或业务中断)、但出于任何责任理论
    、*无论是在合同中、严格责任还是由于
    使用本软件而以任何方式产生的侵权行为(包括疏忽或*其他)
    、*即使已获悉可能会发生此类损坏。
    //
    
    /*
    === i2ctmp116.c ===
    */
    #include 
    #include 
    #include 
    
    /*驱动程序头文件*/
    #include 
    #include 
    #include 
    
    /*驱动程序配置*/
    #include "ti_drivers_config.h"
    
    #define TASKSTACKSIZE 640
    
    /*
    ===== 24C02寄存器====
    */
    
    #define _24C64_REG 0x10;//对于 C64、最大寄存器 val 为0b0001111111111111 = 0x1fff
    #define _24C64_ADDR 0x50;//在7位地址
    
    静态 Display_Handle 显示之前附加0;
    
    //
    *=== mainThread ====
    //
    void * mainThread (void * arg0)
    {
    uint16_t 样本;
    uint16_t 温度;
    uint8_t txBuffer[10];
    uint8_t rxBuffer[10];
    I2C_Handle I2C;
    I2C_Params i2cParams;
    I2C_Transaction i2cTransaction;
    
    /*调用驱动程序初始化函数*/
    display_init();
    GPIO_init();
    I2C_init();
    
    /*配置 LED 以及 TMP116_EN 引脚(如果适用)*/
    GPIO_setConfig (CONFIG_GPIO_LED_0、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    #ifdef CONFIG_GPIO_TMP116_EN
    GPIO_setConfig (CONFIG_GPIO_TMP116_EN、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
    TMP116的/* 1.5ms 复位时间*/
    睡眠(1);
    #endif
    
    /*打开主机显示屏以输出*/
    Display = Display_open (Display_Type_UART、NULL);
    if (display =NULL){
    while (1);
    }
    
    /*打开用户 LED */
    GPIO_WRITE (CONFIG_GPIO_LED_0、CONFIG_GPIO_LED_ON);
    display_printf (display、0、0、"启动 i2c24C64示例\n");
    
    /*创建 I2C 以供使用*/
    I2C_Params_init (&i2cParams);
    i2cParams.bitrate = I2C_100kHz;
    I2C = I2C_open (CONFIG_I2C_TMP、&i2cParams);
    if (i2c == NULL){
    Display_printf (display、0、0、"Error Initializing I2C\n");
    while (1);
    }
    否则{
    display_printf (display、0、0、"I2C initialized!\n"\});
    }
    
    /*通用 I2C 事务设置*/
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 6;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.ReadCount = 0;
    
    display_printf (display、0、0、"写入 EEPROM 的地址0x0000= 0x32");
    txBuffer[0]=_24C64_REG;
    TxBuffer[1]= 0x01;
    TxBuffer[2]= 0x02;
    TxBuffer[3]= 0x03;
    TxBuffer[4]= 0x04;
    txBuffer[5]= 0x05;
    i2cTransaction.slaveAddress =_24C64_ADDR;
    if (!I2C_transfer (i2c、&i2cTransaction))
    {
    Display_printf (display、0、0、"错误。 未找到24C64从 EEPROM! NACK 错误");
    }
    display_printf (display、0、0、"Write successful");
    
    
    /*睡眠1秒*/
    睡眠(1);
    
    
    
    /*
    *读取地址集和读取数据
    *
    Display_printf (display、0、0、"Read part... (r));
    
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.ReadCount = 0;
    txBuffer[0]=_24C64_REG;
    i2cTransaction.slaveAddress =_24C64_ADDR;
    if (!I2C_transfer (i2c、&i2cTransaction))
    {
    Display_printf (display、0、0、"Error...");
    }
    
    
    
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.ReadCount = 10;
    
    
    //
    TxBuffer[1]= 0xA1;
    
    i2cTransaction.slaveAddress =_24C64_ADDR;
    IF (I2C_transfer (i2c、&i2cTransaction))
    {
    Display_printf (display、0、0、"找到24C02从设备 EEPROM!");
    
    对于(采样= 0;采样< 10;+sample)
    {
    温度= rxBuffer[采样];
    display_printf (display、0、0、"value for read[%d]:%x H \r"、sample、temperature);
    }
    
    }
    
    
    
    I2C_Close (i2c);
    display_printf (display、0、0、"I2C closed!");
    
    返回(NULL);
    }
    

    这里是 UART 控制台的输出:

    启动 i2c24C64示例\n></r>
    <\r\n\r\n
    <n></r>
    I2C 已初始化!<n></r>
    <\r\n\r\n
    <n></r>
    写入 EEPROM 的地址0x0000 = 0x32</r>
    <n></r>
    写入成功</r>
    <n></r>
    读取器件... <\r\n\r\n
    <\r\n\r\n
    <n></r>
    24C02从 EEPROM 已找到!</r>
    <n></r>
    读取[0]的值:1H <\r\n>
    <\r\n\r\n
    <n></r>
    读取值[1]:2 H <\r\n\r\n
    <\r\n\r\n
    <n></r>
    读取[2]的值:3 H <\r\n\r\n
    <\r\n\r\n
    <n></r>
    读取[3]的值:4h </r>
    <\r\n\r\n
    <n></r>
    读取[4]的值:5h </r>
    <\r\n\r\n
    <n></r>
    读取值[5]:FF H </r>
    <\r\n\r\n
    <n></r>
    读取的值[6]:FF H <\r\n\r\n
    <\r\n\r\n
    <n></r>
    读取值[7]:FF H <\r\n\r\n
    <\r\n\r\n
    <n></r>
    读取值[8]:FF H <\r\n\r\n
    <\r\n\r\n
    <n></r>
    读取值[9]:FF H <\r\n\r\n
    <\r\n\r\n
    <n></r>
    I2C 已关闭!</r>
    <n></r>