您好,
我使用 Tiva c TM4C129X 开发板、并使用 I2C 协议进行数据传递。
我想将微控制器中的 I2C0用作主器件、将 I2C1用作从器件。
我将 I2C0 SDA 和 SCL 连接 到硼中的 I2C1。 含义: 端口 PB3至 PG1、端口 PG0至 PG2。
我编写了所附的程序、程序卡在" while (I2CMasterBusy (I2C0_BASE)"的循环中
您能不能帮助我解决我的问题。
此致、
Eliran。
#include
#include
#include
#include
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/i2c.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_NVIC.h"
#include "inc/hw_types.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/pin_map.h"
//原型函数
空 I2C0Handler (空);
void I2C1Handler (void);
//主函数
int main()
{
volatile uint32_t SYSCLK=0;
volatile uint32_t recvivied_data=0;
volatile char ch;
//设置时钟
SYSCLK=SysCtlClockFreqSet (SYSCTL_OSC_INT|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_320、16000000);
//启用 i2c 外设
SysCtlPeripheralEnable (SYSCTL_Periph_I2C0); // clk PB2,data PB3
while (!SysCtlPeripheralReady (SYSCTL_Periph_I2C0));
SysCtlPeripheralEnable (sysctl_Periph_I2C1); // clk PG0,data PG1
while (!SysCtlPeripheralReady (SYSCTL_Periph_I2C1));
//设置 i2c 时钟
I2CMasterInitExpClk (I2C0_BASE、SysCtlClockGet ()、true);
//指定要从主器件发送的从器件地址
I2CMasterSlaveAddrSet (I2C0_BASE、0x3B、false);
I2CSlaveInit (I2C1_base、0x3B);
I2CMasterDataPut (I2C0_BASE、'q');
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_SINGLE_SEND);
//启用处理器中断。
// IntMasterEnable();
while (I2CMasterBusy (I2C0_BASE))
{
}
recvived_data=I2CSlaveDataGet (I2C1_base);
ch=(char) recived_data;
返回0;
}
空 I2C0Handler (空)
{
}
空 I2C1Handler (空)
{
}