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.

[参考译文] TM4C129DNCPDT:使用 i2c 时读取错误

Guru**** 2391415 points
Other Parts Discussed in Thread: TM4C129DNCPDT, TMP75

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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/649328/tm4c129dncpdt-error-reading-using-i2c

器件型号:TM4C129DNCPDT
主题中讨论的其他器件: TMP75

你好朋友

我正在处理一个项目、其中我必须读取温度、因此我使用 Tmp75、该项目位于控制器 Tm4c129dncpdt 的 I2C 线路上。
根据 IC 的数据表、我想获取 MSB 和 lsb 值并正确获取温度、但有时我不会经常将 MSB 设置为零、有时会突然设置为0x80。 我不确定这是因为我正在执行的温度 IC 或 I2C 配置。 下面是我在配置中使用的代码

以上是初始化

void Temp_Sensor_init (void)

SysCtlPeripheralEnable (SYSCTL_Periph_I2C0);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOB);

GPIOPinConfigure (GPIO_PB2_I2C0SCL);
GPIOPinConfigure (GPIO_PB3_I2C0SDA);

//配置引脚以用作 I2C 外设的 SCL
GPIOPinTypeI2CSCL (GPIO_PORTB_BASE、GPIO_PIN_2);
//配置 SDA 引脚供 I2C 外设使用。
GPIOPinTypeI2C (GPIO_PORTB_BASE、GPIO_PIN_3);

//将 I2C 时钟设置为100kHz
I2CMasterInitExpClk (I2C0_BASE、g_ui32SysClock、false);


I2CMasterEnable (I2C0_BASE);

ROM_SysCtlDelay (10000);


//针对12位分辨率初始化

I2CMasterSlaveAddrSet (I2C0_BASE、0x4F、false);

I2CMasterDataPut (I2C0_BASE、0x01);

I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_START);

while (I2CMasterBusy (I2C0_BASE))

I2CMasterDataPut (I2C0_BASE、0x60);

I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_SEND_FINISH);

while (I2CMasterBusy (I2C0_BASE))


I2CMasterSlaveAddrSet (I2C0_BASE、0x4F、false);
I2CMasterDataPut (I2C0_BASE、0);
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_SEND);
while (I2CMasterBusy (I2C0_BASE))

在函数下面、我将以循环方式调用它

void Temp_read_Config (uint8_t 从器件、uint8_t reg)

uint8_t data[4]={0};
uint32_t main_data = 0;
uint8_t byte = 0;
float raW_value = 0;

I2CMasterSlaveAddrSet (I2C0_BASE、SLAVE、TRUE);

while (I2CMasterBusy (I2C0_BASE));

I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_Receive_start);

while (I2CMasterBusy (I2C0_BASE));

字节= I2CMasterDataGet (I2C0_BASE);

DATA[0]=字节;

UARTprintf ("Hr:%x\r\n"byte);



I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_Receive_finish);

while (I2CMasterBusy (I2C0_BASE));

ROM_SysCtlDelay (10);
字节= 0;

字节= I2CMasterDataGet (I2C0_BASE);



DATA[1]=字节;

DATA[1]= DATA[1]和0xF0;

数据[1]=数据[1]>> 4;

UARTprintf ("较低:%x\r\n"、字节);

MAIN_DATA =(DATA[0]<< 4)|(DATA[1]);

raW_value =(float)(128*MAIN_DATA)/2048;

memset (temp_data、0、sizeof (temp_data));

sprintf (temp_data、"原始:%f data:%x\r\n"、raW_value、main_data);

UARTprintf (temp_data);


我认为他们在 i2c 配置方面有什么问题

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好 Harish、
    您能不能尝试修改下面的行、看看它是否会产生影响。 由于您有时会获得正确的数据、有时甚至不会获得正确的数据、我建议您使用逻辑分析仪或示波器来捕获总线流量以进行分析。

    修改以下行:
    while (I2CMasterBusy (!I2C0_BASE));

    其中:

    while (!(I2CMasterBusy (I2C0_BASE)));

    while (I2CMasterBusy (I2C0_BASE));