Part Number: TM4C123GH6PM
code
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#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);
//---------------<Write>-------------------//
a=2;
I2CMasterSlaveAddrSet( I2C1_BASE, SLAVE_ADDRESS, false ) ;
I2CMasterDataPut( I2C1_BASE, 0x00) ;
while(I2CMasterBusBusy(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(I2CMasterBusBusy(I2C1_BASE)){}
I2CMasterControl( I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C1_BASE)){}
a=4;
I2CMasterDataPut( I2C1_BASE, DATA ) ;
while(I2CMasterBusBusy(I2C1_BASE)){}
I2CMasterControl( I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH) ;
while(I2CMasterBusy(I2C1_BASE)) {}
a=5;
//---------------<Read>-------------------//
I2CMasterSlaveAddrSet( I2C1_BASE, SLAVE_ADDRESS, false ) ;
I2CMasterDataPut( I2C1_BASE, 0x00 ) ;
while(I2CMasterBusBusy(I2C1_BASE)){}
I2CMasterControl( I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START ) ;
while(I2CMasterBusy(I2C1_BASE)) {}
a=6;
I2CMasterDataPut( I2C1_BASE, WRITE_ADDRESS) ;
while(I2CMasterBusBusy(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(I2CMasterBusBusy(I2C1_BASE)){}
a=8;
I2CMasterControl( I2C1_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE ) ;
while(I2CMasterBusy(I2C1_BASE)){}
// Get Value
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 )
{
}
}