代码
#include
#include
#include
#include
#include
#include
#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/QEI.h"
#include "driverlib/sysctl.h"
#include "driverlib/pwm.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "math.h"
#include "driverlib/i2c.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
void Init_Clk (void);
void Init_Timer( void );
void Timer0_ISR( void );
void Init_I2C( void );
#define SLAVE_ADDRESS 0x50
#define WRITE_ADDRESS 0x01
#define DATA 0xAB
int a=0;
volatile long Cnt32_1 = 0;
int b=0;
void Init_I2C( void )
{
A=1;
SysCtlPeripheralEnable (SYSCTL_Periph_I2C1);
SysCtlPeripheralEnable( sysctl_Periph_GPIOA);
GPIOPinConfigure (GPIO_PA6_I2C1SCL);
GPIOPinConfigure (GPIO_PA7_I2C1SDA);
GPIOPinTypeI2CSCL (GPIO_Porta_base、GPIO_PIN_6);
GPIOPinTypeI2C (GPIO_Porta_base、GPIO_PIN_7);
I2CMasterInitExpClk (I2C1_base、SysCtlClockGet ()/100、false);
I2CMasterEnable (I2C1_base);
///-------- ---------- //
A=2;
I2CMasterSlaveAddrSet( I2C1_base、slave_address、false );
I2CMasterDataPut (I2C1_base、0x00);
while (I2CMasterBusy (I2C1_base)){}
I2CMasterControl (I2C1_base、I2C_MASTER_CMD_BURST_SEND_START);
while (I2CMasterBusy (I2C1_base)){}
A=3;
I2CMasterDataPut (I2C1_base、write_address);
A=10;
while (I2CMasterBusy (I2C1_base)){}
I2CMasterControl (I2C1_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C1_base)){}
A=4;
I2CMasterDataPut( I2C1_base,data );
while (I2CMasterBusy (I2C1_base)){}
I2CMasterControl (I2C1_base、I2C_MASTER_CMD_BURST_SEND_FINISH);
while (I2CMasterBusy (I2C1_base)){}
A=5;
///-------- ---------- //
I2CMasterSlaveAddrSet( I2C1_base、slave_address、false );
I2CMasterDataPut( I2C1_base,0x00 );
while (I2CMasterBusy (I2C1_base)){}
I2CMasterControl( I2C1_base、I2C_MASTER_CMD_BURST_SEND_START );
while (I2CMasterBusy (I2C1_base)){}
A=6;
I2CMasterDataPut (I2C1_base、write_address);
while (I2CMasterBusy (I2C1_base)){}
I2CMasterControl (I2C1_base、I2C_MASTER_CMD_BURST_SEND_CONT);
while (I2CMasterBusy (I2C1_base)){}
A=7;
I2CMasterSlaveAddrSet( I2C1_base、slave_address、true );
while (I2CMasterBusy (I2C1_base)){}
while (I2CMasterBusy (I2C1_base)){}
A=8;
I2CMasterControl( I2C1_base、I2C_MASTER_CMD_SINGLE_Receive );
while (I2CMasterBusy (I2C1_base)){}
//获取值
Cnt32_1 = I2CMasterDataGet (I2C1_base);
}
void main (void)
{
SysCtlClockSet (SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHz | SYSCTL_OSC_MAIN);
init_i2c();
while (1)
{
}
}