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.

[参考译文] CCS/TM4C1294NCPDT:I2C CAN#39;t 读取真实温度值

Guru**** 2434370 points
Other Parts Discussed in Thread: LM75A

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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/758304/ccs-tm4c1294ncpdt-i2c-can-t-read-true-temperature-value

器件型号:TM4C1294NCPDT
主题中讨论的其他器件:LM75A

工具/软件:Code Composer Studio

我可以在振荡器上观察 i2c 时钟信号、它工作正常。 这意味着我将数据主器件发送到从器件。  

我使用 lm75a 作为温度传感器的从器件。 我在从从器件读取数据时遇到问题。 我读取值、但它不会改变。 这意味着它不是温度、或者我读取的值是多少?

我的代码如下所示:

#include 
#include 
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.idrultrloop"




(#idvolatile t32xtinc)#id_zh_idle 0xtid_inc 0x32h void #include "id_inc 0xtid_zh-inc

0x32h (#define)
for (ui32Loop = 0;ui32Loop < 200;ui32Loop +);
}


volatile uint32_t result[7];
uint32_t g_ui32SysClock;

uint32_t TempValueC;

int main (void)
{


printf ("\n hello0\n");
// g_ui32SysClock = SysCtlClockFreqSet (((SYSCTL_OSC_main | SYSCTL_XTAL_25MHz | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320)、40000000);
//
//启用用于板载 LED 的 GPIO 端口。
//
SYSCTL_RCGCGPIO_R = SYSCTL_RCGCGPIO_R3 | SYSCTL_RCGCGPIO_R9 | SYSCTL_RCGCGPIO_R1;
//
//执行虚拟读取以在启用外设后插入几个周期。
//
printf ("\n hello1 \n");
//结果= SYSCTL_RCGCGPIO_R;
//
//为 LED 启用 GPIO 引脚(PD3)。 将方向设置为输出、然后
//启用 GPIO 引脚以实现数字功能。
//
//// GPIO_PORTD_AHB_DIR_= 0x8;
//GPIO_PORTD_AHB_DEN_R = 0x8;
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOK);
SYSCTL_RCGCI2C_R =(1 << 7)|(1 << 6);// I2C 模块4和6的模式时钟门控控制

GPIOPinConfigure (GPIO_PK6_I2C4SCL);
GPIOPinConfigure (GPIO_PK7_I2C4SDA);
//GPIOPinConfigure (GPIO_PA6_I2C6SCL);
// GPIOPinConfigure (GPIO_PA7_I2C6SDA);
SysCtlPeripheralEnable (SYSCTL_Periph_I2C4);
printf ("\n hello2 \n");
GPIOPinTypeI2C (GPIO_PORTK_base、(1 << 7));
printf ("\n hellloa \n");//配置 SDA
GPIOPinTypeI2CSCL (GPIO_PORTK_base、(1 << 6));
printf ("\n hellob \n");//配置 SCL
//GPIOPinTypeI2C (GPIO_PORta_base、(1 << 7));
printf ("\n helloc \n");//配置 SDA
//GPIOPinTypeI2CSCL (GPIO_Porta_base、(1 << 6));//配置 SCL
printf ("\n hello4 \n");
I2CMasterInitExpClk (I2C4_base、g_ui32SysClock、false);
printf ("\n hello5 \n");
I2CSlaveEnable (I2C4_base);
I2CSlaveInit (I2C4_base、slave_address);
I2CMasterSlaveAddrSet (I2C4_base、slave_address、false);
printf ("\n hello6 \n");
//
//永久循环。
//
while (1)
{

printf ("\n1\n");
I2CMasterDataPut (I2C4_base、slave_address);
printf ("\n2\n");
I2CMasterControl (I2C4_base、I2C_MASTER_CMD_SINGLE_SEND);
printf ("\n 3\n");
//
//等待从机接收并确认数据。
//
//while (!(I2CSlaveStatus (I2C4_base)& I2C_SLAVE_ACT_RREQ));
//
//从从从器件读取数据。
printf ("\n 4\n");
Result [7]= I2CSlaveDataGet (I2C4_base);
//结果= I2CSlaveDataGet (I2C4_base);
printf ("\n 5\n");

printf ("\n%d\n"、结果);

TempValueC =(147.5 -((75.0 * 3.3 * Result [0]))/ 4096.0);
printf ("%d"、TempValueC);
while (I2CMasterBusy (I2C4_base));
//
//延迟一位。
//
延迟();


//延迟一位。
//
延迟();
}
}



  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我想您首先阅读 LM75A 数据表、了解如何读取/写入 LM75A 寄存器。 当您查看示波器时、您是否具有正确的地址字节、它是否被从器件正确确认? 当您说您没有读取温度时、它在示波器上显示什么? 捕获示波器并显示它是什么。

    我看到您调用 I2CMasterDataPut (I2C4_base、slave_address)。 它的用途是什么? 如果您正在读取温度、则无需生成指针字节、因为上电后指针字节默认为0、指向温度寄存器。 据我所知,您不需要 I2CMasterDataPut()。 在任何情况下、请查看 LM75A 数据表、并根据数据表验证您的示波器捕获。