I2C上与LM77的FTDI FT232H通信

发布于 2025-01-22 14:52:17 字数 2149 浏览 1 评论 0原文

我正在尝试使用I2C通信和FTDI FT232H从LM77获得温度读数。我认为这不是一个硬件问题,因为我已经与多个同事一起检查了连接。与PC与FT232H的通信还可以,它是初始化的,并且一切都很好。 FT232H发送读取字节,并从LM77获得ACK。之后,没有更多的数据。我希望LM77向温度读数发送10位数据,但事实并非如此。这就是逻辑探针上的读数。

我希望随后看到另外两个字节在ACK之后出现,但一无所获。代码非常简单,我正在使用libmpsse i2c API。我使用的0x48的地址来自数据表中给出的地址,将位置在1中移动。我不明白为什么我会得到ACK,但之后没有温度读数。读取的FTSTATU给出了错误代码ft_device_not_found。我不确定如果有ACK,为什么会提供此错误代码。

#include <stdio.h>
#include <stdlib.h>
#include "libMPSSE_i2c.h"

#define DEVICE_ADDR 0x48

FT_STATUS ftStatus;
FT_HANDLE ftHandle;

int i2cInit(void)
{
    int numChannels = 0;
    FT_DEVICE_LIST_INFO_NODE chanInfo;
    ChannelConfig chConfig = {.ClockRate = 100000,
                              .LatencyTimer = 255,
                              .Options = 0x0000};
    ftStatus = I2C_GetNumChannels(&numChannels);
    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Number of channels: %d\n", numChannels);
    }

    ftStatus = I2C_GetChannelInfo(0, &chanInfo);

    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Channel info obtained\n");
    }

    ftStatus = I2C_OpenChannel(0, &ftHandle);
    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Channel opened\n");
    }

    ftStatus = I2C_InitChannel(ftHandle, &chConfig);
    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Channel initialized\n");
    }

}


int lm77ReadTemp()
{
    unsigned char writeBuffer[20] = {0};
    unsigned char readBuffer[20] = {0};
    unsigned char bytesTransferred = 0;
    unsigned int bytesRead = 0;

    ftStatus = I2C_DeviceRead(ftHandle, DEVICE_ADDR, 2, readBuffer, &bytesRead, I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_STOP_BIT);
    if (ftStatus != FT_OK)
    {
        printf("Read failed status code %d\n", ftStatus);
    }
    
}

int main(void)
{
    i2cInit();
    lm77ReadTemp();
    return 0;
}

I am trying to get a temperature readout from a LM77 using I2C communication with and FTDI FT232H. I don't think it is a hardware problem since I have checked the connections along with multiple colleagues. The communication with the PC to the FT232H is okay, it is initializing and everything is good on that end. The FT232H sends a read setup byte and gets an ACK from the LM77. After that there is no more data. I expect the LM77 to send 10 bits of data for a temperature readout, but it is not. This is what the readout looks like on a logic probe. enter image description here

I would expect to then see an additional two bytes come in after the ACK but am getting nothing. The code is pretty straightforward and I am using the libMPSSE I2C API. The address I am using 0x48 comes from the address given in the datasheet bit shifted right by 1. I do not understand why I am getting an ACK but no temperature readout after. The ftStatus for the read gives an error code FT_DEVICE_NOT_FOUND. I am not sure why it's giving this error code if there is an ACK.

#include <stdio.h>
#include <stdlib.h>
#include "libMPSSE_i2c.h"

#define DEVICE_ADDR 0x48

FT_STATUS ftStatus;
FT_HANDLE ftHandle;

int i2cInit(void)
{
    int numChannels = 0;
    FT_DEVICE_LIST_INFO_NODE chanInfo;
    ChannelConfig chConfig = {.ClockRate = 100000,
                              .LatencyTimer = 255,
                              .Options = 0x0000};
    ftStatus = I2C_GetNumChannels(&numChannels);
    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Number of channels: %d\n", numChannels);
    }

    ftStatus = I2C_GetChannelInfo(0, &chanInfo);

    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Channel info obtained\n");
    }

    ftStatus = I2C_OpenChannel(0, &ftHandle);
    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Channel opened\n");
    }

    ftStatus = I2C_InitChannel(ftHandle, &chConfig);
    if (ftStatus != FT_OK)
    {
        return -1;
    }

    else
    {
        printf("Channel initialized\n");
    }

}


int lm77ReadTemp()
{
    unsigned char writeBuffer[20] = {0};
    unsigned char readBuffer[20] = {0};
    unsigned char bytesTransferred = 0;
    unsigned int bytesRead = 0;

    ftStatus = I2C_DeviceRead(ftHandle, DEVICE_ADDR, 2, readBuffer, &bytesRead, I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_STOP_BIT);
    if (ftStatus != FT_OK)
    {
        printf("Read failed status code %d\n", ftStatus);
    }
    
}

int main(void)
{
    i2cInit();
    lm77ReadTemp();
    return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2025-01-29 14:52:17

问题在硬件方面。 MPSSE发动机没有双向引脚。在FTDI芯片侧,您需要一个单独的PIN pin sda_out和sda_in。 FTDI文档中有一个图表。如果您没有像这样连接的引脚,则不会从I2C奴隶那里收到任何数据。

The problem was on the hardware side. The MPSSE engine does not have bidirectional pins. On the FTDI chip side, you need a separate pin for SDA_out and SDA_in. There is a diagram in the FTDI documentation that shows it. If you don't have the pins connected like this you won't receive any data from the I2C slave. enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文