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.

[参考译文] TM4C123GH6PM:I2C 通信

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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/626702/tm4c123gh6pm-i2c-communication

器件型号:TM4C123GH6PM

您好!

我正在使用 TM4C123GH6PM 微控制器。 (Tiva c launchpad)。

我正在尝试使用 i2c 通信与 RTC 模块(DS3231)通信。

我正在尝试示例代码。 (主从回路机制)。

现在,我尝试使用 Out loop back 机制。 简单的主从器件发送和接收。 (我不能访问回送机制)。

但我无法将任何数据传输到 RTC 模块。  我将代码复制到下面。  

是否有任何错误意味着任何错误、请向我推荐任何解决方案。

计划:

#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.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"

#define NUM_I2C_DATA 8.

#define SLAVE_ADDRESS 0xD0          //从地址

无效
InitConsole (空)

 SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA);

GPIOPinConfigure (GPIO_PA0_U0RX);

GPIOPinConfigure (GPIO_PA1_U0TX);

SysCtlPeripheralEnable (SYSCTL_Periph_UART0);

UARTClockSourceSet (UART0_BASE、UART_CLOCK_PIOSC);

GPIOPinTypeUART (GPIO_Porta_base、GPIO_PIN_0 | GPIO_PIN_1);

UARTStdioConfig (0、115200、16000000);

int main (空)

uint32_t ui32Index = 0;
uint32_t pui32DataTx[8]={0};
uint32_t pui32DataRx[8]={0};

SysCtlClockSet (SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHz | SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable (SYSCTL_Periph_I2C0);

SysCtlPeripheralEnable (SYSCTL_Periph_GPIOB);

GPIOPinConfigure (GPIO_PB2_I2C0SCL);
GPIOPinConfigure (GPIO_PB3_I2C0SDA);

GPIOPinTypeI2CSCL (GPIO_PORTB_BASE、GPIO_PIN_2);
GPIOPinTypeI2C (GPIO_PORTB_BASE、GPIO_PIN_3);

 I2CMasterInitExpClk (I2C0_BASE、SysCtlClockGet ()、false);

 I2CSlaveEnable (I2C0_BASE);

I2CSlaveInit (I2C0_BASE、SLAVE_ADDRESS);

I2CMasterSlaveAddrSet (I2C0_BASE、SLAVE_ADDRESS、FALSE);      //用于写入

 InitConsole();

pui32DataTx[0]='I';
I2CMasterDataPut (I2C0_BASE、pui32DataTx[ui32Index]);

 I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_SEND);

while (!(I2CSlaveStatus (I2C0_BASE)& I2C_SLAVE_ACT_RREQ))                //我的代码将仅停留在此处。 之后、它不会移动。

pui32DataRx[ui32Index]= I2CSlaveDataGet (I2C0_BASE);

while (I2CMasterBusy (I2C0_BASE))

此致

Arun Kumar.N

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    尊敬的 Arun:
    您能否首先确认您在 I2C 总线上的 SCL 和 SDA 上是否具有正确的上拉电阻器?