Other Parts Discussed in Thread: EK-TM4C1294XL
Hello,
I'm having problems interfacing my TM4C MCU to a MMA 7455 accelerometer.
I continuelly receive the Arbitration Lost error.
Fist I just wanted to write to the 0x16 register of the accelerometer to set it't mode and only after that to receive data from it.
But I have issues sending data.
I check the MCS register and no sign of setting the run / start / end condition bits (0,1,2).
Also the MDR register is always empty.
I paste here the function to initialize the I2C Master and the function to write data from the master (MCU) to slave (MMA 7455).
Init Function:
void I2C_Accelerometer_Init(void)
{
//Init PB2 as I2C_0 SCL and PB3 as I2C_0 SDA
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); //The I2C0 peripheral must be enabled for use.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //The GPIOB peripheral must be enabled for use.
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configure PUR for PB2
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD); //Configure OD for PB3
GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_2|GPIO_PIN_3, GPIO_DIR_MODE_HW); //Set direction by HW for PB2 and PB3
I2CMasterInitExpClk(I2C0_BASE,SYS_clock_get,0); //Set System clock and normal (100 kbps) transfer rate for I2C_0
}
I2C Write Function:
unsigned char I2C_Write(unsigned char Slave_Address, unsigned char Register_Address, unsigned char Register_Value)
{
unsigned char error_nr = 0;
//Step 1. Set Slave address and Write mode (R/W bit = 0)
I2CMasterSlaveAddrSet(I2C0_BASE,Slave_Address,Master_Tx_Slave_Rx); //Set slave address and send mode
//Step 2. Send the 8bit register address to write to
I2CMasterDataPut(I2C0_BASE, Register_Address); //Send the register address to the Slave device
while(I2CMasterBusBusy(I2C0_BASE)){}
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE)){}
error_nr = I2CMasterErr(I2C0_BASE);
if(error_nr !=0)
{
if(error_nr ==0x10)
{
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_ERROR_STOP);
}
return 0; //Error Service
}
else
{
//Step 3. Send data to write on register
I2CMasterDataPut(I2C0_BASE, Register_Value); //Send the register value to the Slave device
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_BASE)){}
error_nr = I2CMasterErr(I2C0_BASE);
if(error_nr !=0)
{
return 0;
}
return 1;
}
}
So if you have any idea on what did I do wrong, please let me know.
I've been struggeling to find the issue for a few days already.
Thanks & Regards,
Alex
