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:与 CC3220sf 进行 I2C 连接

Guru**** 2540720 points
Other Parts Discussed in Thread: CC3220SF, TMP006, TMP102

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

https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/754628/cc3220sf-launchxl-i2c-interfacing-with-cc3220sf

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

您好、

我将 CC3220sf 与 am2315连接。 我正在使用 tmp 驱动程序、但遇到 I2C 总线故障。 此外、还在控制器和传感器之间使用电平转换器。 电平转换器电路与节点 MCU 12-e 和传感器一起工作以获取值。 J15、J16和 J24在电路板上处于开路状态。 代码为:

#include

#include

#include

/*驱动程序头文件*/

#include

#include

#include

/*示例/板头文件*/

#include "Board.h"

//#define TMP006_ADDR     0x41

//#define TMP006_DIE_TEMP  0x0001 //*裸片温度结果寄存器*/

//#ifndef Board_TMP_ADDR

//#define Board_TMP_ADDR   TMP006_ADDR

//#endif

静态 Display_Handle 显示;

/*

 * ==== mainThread ====

 *

void * mainThread (void * arg0)

  unsigned int  i;

  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 引脚*/

  GPIO_setConfig (Board_GPIO_LED0、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

  /*打开主机显示屏以输出*/

  Display = Display_open (Display_Type_UART、NULL);

  if (display =NULL){

    while (1);

  }

  /*打开用户 LED */

  GPIO_WRITE (Board_GPIO_LED0、Board_GPIO_LED_ON);

  display_printf (display、0、0、"启动 i2ctmp006示例\n");

  /*创建 I2C 以供使用*/

  I2C_Params_init (&i2cParams);

  i2cParams.bitrate = I2C_100kHz;

  I2C = I2C_open (Board_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"\});

  }

/*指向 T 环境寄存器并读取其2个字节*/

  TxBuffer[0]= 0x03;

  TxBuffer[1]= 0x00;

  txBuffer[2]= 4;

  i2cTransaction.slaveAddress = 0x5C;

  i2cTransaction.writeBuf = txBuffer;

  i2cTransaction.writeCount = 3;

  i2cTransaction.readBuf = rxBuffer;

  i2cTransaction.ReadCount = 10;

  /*采集20个样本并将其打印到控制台*/

  对于(I = 0;I < 5;I++)

  {

    IF (I2C_transfer (i2c、&i2cTransaction))

    {

      /*从接收到的数据中提取°C;请参阅 TMP102数据表*/

      睡眠(1);

      湿度= rxBuffer[2];

      Display_printf (display、0、0、"接收到的缓冲区%d (C)\n"、rxBuffer[2]);

      湿度=湿度* 256;

      湿度=湿度+ rxBuffer[3];

      湿度=湿度/10;

      温度= rxBuffer[4]和0x7F;

      温度=温度* 256;

      温度=温度+ rxBuffer[5];

      温度=温度/10;

      if (rxBuffer[4]>> 7)

      {

        温度=-温度;

      }

      display_printf (display、0、0、"Sample %u:%d (C)\n"、i、temperature);

    }

    否则{

      display_printf (display、0、0、"I2C 总线故障\n"\});

    }

    /*睡眠1秒*/

    睡眠(1);

  }

  /*已取消初始化 I2C */

  I2C_Close (i2c);

  display_printf (display、0、0、"I2C closed!\n"\});

  返回(0);

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

    您好!

    请坚持原始 帖子。 我没有忘记它。  

    Jesu