hi ,
i work with tiva c TM4C129X development board and i am trynig to pass data with I2C protocol.
i want to use I2C0 in the microcontroller as Master and with I2C1 as slave.
i connected I2C0 SDA and SCL to I2C1 in the borad. meaning: port PB3 to PG1 and port PG0 to PG2.
i wrote the attached program and the program is stuck in the loop in " while(I2CMasterBusy(I2C0_BASE)) "
can you please help me with what am i doing wrong.
best regards,
Eliran.
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#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"
// PROTOTYPE FUNCTIONS
void I2C0Handler(void);
void I2C1Handler(void);
// main function
int main()
{
volatile uint32_t SysClk=0;
volatile uint32_t RECEVIED_DATA=0;
volatile char ch;
// set clock
SysClk=SysCtlClockFreqSet(SYSCTL_OSC_INT|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_320,16000000);
// Enable i2c peripheral
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));
//set i2c clock
I2CMasterInitExpClk(I2C0_BASE,SysCtlClockGet(),true);
// specify slave address to send from the master
I2CMasterSlaveAddrSet(I2C0_BASE,0x3B,false);
I2CSlaveInit(I2C1_BASE,0x3B);
I2CMasterDataPut(I2C0_BASE,'q');
I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_SINGLE_SEND);
// Enable processor interrupts.
// IntMasterEnable();
while(I2CMasterBusy(I2C0_BASE))
{
}
RECEVIED_DATA=I2CSlaveDataGet(I2C1_BASE);
ch=(char)RECEVIED_DATA;
return 0;
}
void I2C0Handler(void)
{
}
void I2C1Handler(void)
{
}