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.

[参考译文] TM4C129ENCPDT:I2C2 - I2CMasterBusy (I2C2_base)

Guru**** 2440240 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/627399/tm4c129encpdt-i2c2---i2cmasterbusy-i2c2_base

器件型号:TM4C129ENCPDT

大家好、

我正在尝试从 I2C 从设备获取一些数据、但 使用 I2C2时程序卡在 I2CMasterBusy (I2C2_base)中。 我无法获得任何具有示波器的信号。 我在 SCL 和 SDA 中有上拉电阻器。

当我尝试使用 I2C5时、它工作正常。

我可以在这个问题上找到一些方向、对吧?

#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/sysctexample.uint8 uart_univers"



#define
#define "driverlib/uint8 uart_univers.u.uint8 u.uinth


"#define #define #define #define "driverlib/uintuint8 uint_uintuart.uart.h "#define #define #include "driverlib/uart.int8 uint_uart.uart.uart.h #define #define #include


//指定我们要向写入(寄存器地址)
//从器件
I2CMasterSlaveAddrSet (I2C2_base、slave_addr、false);

//指定要读取的寄存器
I2CMasterDataPut (I2C2_base、reg);

//将控制字节和寄存器地址字节发送到从器件
I2CMasterControl (I2C2_base、I2C_MASTER_CMD_BURST_SEND_START);

SysCtlDelay (100);
//等待 MCU 完成事务
while (!(I2CMasterBusy (I2C2_base)));
SysCtlDelay (100);
while (I2CMasterBusy (I2C2_base));

//指定我们将从从从器件读取
I2CMasterSlaveAddrSet (I2C2_base、slave_addr、true);

//发送控制字节并从我们的寄存器中读取
//specified
I2CMasterControl (I2C2_base、I2C_MASTER_CMD_SINGLE_Receive);

SysCtlDelay (100);
//等待 MCU 完成事务
while (!(I2CMasterBusy (I2C2_base)));
SysCtlDelay (100);
while (I2CMasterBusy (I2C2_base));

//返回从指定寄存器提取的数据
返回 I2CMasterDataGet (I2C2_base);
}

//*********
//
//配置 I2C5主设备。
////
*****************
volatile uint32_t test = 0;
void
main (void)
{
uint32_t ui32SysClock;

ui32SysClock = SysCtlClockFreqSet ((SYSCTL_OSC_INT | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480)、120000000);

//
//使用前必须启用 I2C2外设。
//
SysCtlPeripheralEnable (SYSCTL_Periph_I2C2);
while (!SysCtlPeripheralReady (SYSCTL_Periph_I2C2))
{}

SysCtlPeripheralEnable (SYSCTL_Periph_GPION);

GPIOPinConfigure (GPIO_PN4_I2C2SDA);
GPIOPinConfigure (GPIO_PN5_I2C2SCL);

GPIOPinTypeI2CSCL (GPIO_PORTN_BASE、GPIO_PIN_5);
GPIOPinTypeI2C (GPIO_PORTN_BASE、GPIO_PIN_4);

I2CMasterInitExpClk (I2C2_base、ui32SysClock、false);


//在外部连接器中启用电源
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOJ);
GPIOPinTypeGPIOOutput (GPIO_PORTJ_BASE、GPIO_PIN_0);
GPIOPinWrite (GPIO_PORTJ_BASE、GPIO_PIN_0、~0);

for (;;){
TEST = I2CReceive (register、ID_address);
SysCtlDelay (60000000);//~500ms
}

}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好、Allef、
    如果它适用于 I2C5、则适用于 I2C2。 一个有趣的事情是调用 I2CReceive (register、ID_address)。 您为什么传递等于0的寄存器作为从地址? ID_ADDRESS 也定义为什么?
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Charles!

    我很抱歉。 我在经过这里之前更改了定义。 我现在正在调试硬件。 以下是正确的代码。

    #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/sysctex.10uart"
    
    
    
    #define #define "driverlib/uart.h"#define #include "driverlib/sysctole.h"#define #define #dio.10uarth register #define #include "dio.10uart"#define #include "dio.
    0x01
    
    
    //从器件
    uint32_t I2CReceive (uint8_t slave_addr、uint8_t reg)
    上的读取指定寄存器{
    //指定我们要向写入(寄存器地址)
    //从器件
    I2CMasterSlaveAddrSet (I2C2_base、slave_addr、false);
    
    //指定要读取的寄存器
    I2CMasterDataPut (I2C2_base、reg);
    
    //将控制字节和寄存器地址字节发送到从器件
    I2CMasterControl (I2C2_base、I2C_MASTER_CMD_BURST_SEND_START);
    
    //等待 MCU 完成事务
    while (!(I2CMasterBusy (I2C2_base)));
    while (I2CMasterBusy (I2C2_base));
    
    //指定我们将从从从器件读取
    I2CMasterSlaveAddrSet (I2C2_base、slave_addr、true);
    
    //发送控制字节并从我们的寄存器中读取
    //specified
    I2CMasterControl (I2C2_base、I2C_MASTER_CMD_SINGLE_Receive);
    
    //等待 MCU 完成事务
    while (!(I2CMasterBusy (I2C2_base)));
    while (I2CMasterBusy (I2C2_base));
    
    //返回从指定寄存器提取的数据
    返回 I2CMasterDataGet (I2C2_base);
    }
    
    //*********
    //
    //配置 I2C5主设备。
    ////
    *****************
    volatile uint32_t test = 0;
    void
    main (void)
    {
    uint32_t ui32SysClock;
    
    ui32SysClock = SysCtlClockFreqSet ((SYSCTL_OSC_INT | SYSCTL_USE_PLL |
    SYSCTL_CFG_VCO_480)、120000000);
    
    //
    //使用前必须启用 I2C2外设。
    //
    SysCtlPeripheralEnable (SYSCTL_Periph_I2C2);
    while (!SysCtlPeripheralReady (SYSCTL_Periph_I2C2))
    {}
    
    SysCtlPeripheralEnable (SYSCTL_Periph_GPION);
    
    GPIOPinConfigure (GPIO_PN4_I2C2SDA);
    GPIOPinConfigure (GPIO_PN5_I2C2SCL);
    
    GPIOPinTypeI2CSCL (GPIO_PORTN_BASE、GPIO_PIN_5);
    GPIOPinTypeI2C (GPIO_PORTN_BASE、GPIO_PIN_4);
    
    I2CMasterInitExpClk (I2C2_base、ui32SysClock、false);
    
    
    //在外部连接器中启用电源
    SysCtlPeripheralEnable (SYSCTL_Periph_GPIOJ);
    GPIOPinTypeGPIOOutput (GPIO_PORTJ_BASE、GPIO_PIN_0);
    GPIOPinWrite (GPIO_PORTJ_BASE、GPIO_PIN_0、~0);
    
    for (;;){
    TEST = I2CReceive (SLAVE_ADDRESS、寄存器);
    SysCtlDelay (60000000);//~500ms
    }
    
    }