We are trying to send a message from one I2C Module to another on the TM4c123g. Therefore we initialized I2C0 as a Master and I2C1 as a Slave.
We used external pullup resistors.
When the message is received by the Slave the clock stays down and there is no further communication. The first Message sent is adressed to a Slave that doesnt exist. This was made to prove that only received messages cause the problem.
Thanks ;)
#include <stdint.h>
#include <stdbool.h>
#include "stdlib.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_uart.h"
#include "inc/hw_gpio.h"
#include "inc/hw_timer.h"
#include "inc/hw_types.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/debug.h"
#include "driverlib/systick.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/udma.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/i2c.h"
#include <string.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
static uint32_t g_ui32DataRx;
void InitI2C0(void) //Master
{
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(), true);
}
void InitI2C1(void) //Slave
{
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);
}
// The interrupt handler for the for I2C1 data slave interrupt.
void I2C1SlaveIntHandler(void)
{
I2CSlaveIntClear(I2C1_BASE);
g_ui32DataRx = I2CSlaveDataGet(I2C1_BASE);
I2CSlaveStatus(I2C1_BASE);
}
int main(void) {
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
InitI2C0();
InitI2C1();
IntEnable(INT_I2C1);
I2CSlaveIntEnableEx(I2C1_BASE,I2C_SLAVE_INT_DATA);
I2CSlaveEnable(I2C1_BASE);
I2CSlaveInit(I2C1_BASE,0x3b);
IntMasterEnable();
while(1){
I2CMasterSlaveAddrSet(I2C0_BASE, 0x2b, false);
I2CMasterDataPut(I2C0_BASE,5);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE));
I2CMasterSlaveAddrSet(I2C0_BASE, 0x3b, false);
I2CMasterDataPut(I2C0_BASE,1);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE));
}
}