Hi everybody, I new here and I need your experience and assistance. I'm in a new project (Self Leveling Platform) and I'm having many troubles with I2C module. In the first instance I want to write and read data from a register of my accelerometer (whichever), but in Code Composer Studio I see in I2C0 register, I2C_MCS_STOP = I2C_MCS_ADRACK = I2C_MCS_ERROR = 0 always and it never changes, and I don't know why, here is my code:
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"
#include "inc/hw_i2c.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/i2c.h"
#include "driverlib/systick.h"
#include "string.h"
int a;
void bus(void){
HWREG(I2C0_MASTER_BASE + I2C_O_MCR) |= 0x01;
I2CMasterEnable(I2C0_MASTER_BASE);
//delay();
I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), true);
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, (0x30 >> 1), false);
I2CMasterDataPut(I2C0_MASTER_BASE, 0x20);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_MASTER_BASE)) {}
I2CMasterDataPut(I2C0_MASTER_BASE, 0x27);
I2CMasterDataPut(I2C0_MASTER_BASE, 0x23);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_MASTER_BASE)) {}
I2CMasterDataPut(I2C0_MASTER_BASE, 0x30);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_MASTER_BASE)) {}
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, (0x32 >> 1), true);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusy(I2C0_MASTER_BASE)) {}
a=I2CMasterDataGet(I2C0_MASTER_BASE);
while (I2CMasterBusBusy(I2C0_MASTER_BASE)){}
}
int main(void)
{
//
// Setup the system clock to run at 50 Mhz from PLL with crystal reference
//
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
SYSCTL_OSC_MAIN);
//SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//
//SysCtlPeripheralPowerOn(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Enable port PB2 for I2C0 I2C0SCL
//
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
//
// Enable port PB3 for I2C0 I2C0SDA
//
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0);
//
// Loop Forever
//
while(1)
{
bus();
}
}
I have no idea what is wrong.
Here is the link of the accelerometer datasheet, http://www.pololu.com/file/download/LSM303DLM.pdf?file_id=0J514
BTW, I have not much experience in bus I2C, I'm learning about it.
Sorry for my English.
thank you very much in advance!!