hi
have problems reading sensor X,Y,Z values. I initialise the ADXL345 is with CCS version 6.0 and TivaWare_C_Series-2.1.0.12573.
and recieved value 0XE5 from 0X00 address.
my problem start from next step here i initialise power mode 0X08 at 0X2D and senor data read from 0X32. bt it gives me value 0X00..
please help me to solve this problem.
here is my initialisation
I2Cinit(){
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//
// Configure the pin muxing for I2C7 functions on port D0 and D1.
// This step is not necessary if your part does not support pin muxing.
//
// For BoosterPack 2 interface use PA2 and PA3.
//
ROM_GPIOPinConfigure(GPIO_PD0_I2C7SCL);
ROM_GPIOPinConfigure(GPIO_PD1_I2C7SDA);
//
// Select the I2C function for these pins. This function will also
// configure the GPIO pins pins for I2C operation, setting them to
// open-drain operation with weak pull-ups. Consult the data sheet
// to see which functions are allocated per pin.
//
// For BoosterPack 2 interface use PA2 and PA3.
//
ROM_GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
//
// Keep only some parts of the systems running while in sleep mode.
// GPIOE is for the ISL29023 interrupt pin.
// UART0 is the virtual serial port
// I2C7 is the I2C interface to the ISL29023
//
// For BoosterPack 2 change this to I2C8.
//
ROM_SysCtlPeripheralClockGating(true);
//ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE);
ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C7);
//
// Configure desired interrupt priorities. Setting the I2C interrupt to be
// of more priority than SysTick and the GPIO interrupt means those
// interrupt routines can use the I2CM_DRV Application context does not use
// I2CM_DRV API and GPIO and SysTick are at the same priority level. This
// prevents re-entrancy problems with I2CM_DRV but keeps the MCU in sleep
// state as much as possible. UART is at least priority so it can operate
// in the background.
//
// For BoosterPack 2 use I2C8.
//
ROM_IntPrioritySet(INT_I2C7, 0x00);
pfAccel = pfData;
I2CMInit(&g_sI2CInst3, I2C7_BASE, INT_I2C7, 0xff, 0xff, g_ui32SysClock);
ADXL345Init(&g_sADXL345Inst, &g_sI2CInst3, ADXL345_I2C_ADDRESS,
ISL29023AppCallback, &g_sADXL345Inst);
ISL29023AppI2CWait(__FILE__, __LINE__);
ROM_SysCtlDelay(g_ui32SysClock / (30 * 3));
g_vui8DataFlag = 0;
SysCtlDelay(g_ui32SysClock/ (30 * 3));
ADXL345DataRead(&g_sADXL345Inst, ISL29023AppCallback, &g_sADXL345Inst);
ISL29023AppI2CWait(__FILE__, __LINE__);
ROM_SysCtlDelay(g_ui32SysClock / (30 * 3));
if(g_sADXL345Inst.pui8Data[0]==0XE5)
{
adxl_data=g_sADXL345Inst.pui8Data[0];
ADXL345_FLAG=1;
}
SysCtlDelay(g_ui32SysClock/ (30 * 3));
ADXL345DataRead(&g_sADXL345Inst, ISL29023AppCallback, &g_sADXL345Inst);
ISL29023AppI2CWait(__FILE__, __LINE__);
ROM_SysCtlDelay(g_ui32SysClock / (30 * 3));
adxl_data=g_sADXL345Inst.pui8Data[0]|(1<<3);
adxl_data=adxl_data|(1<<3);
UARTprintf("adxl_data==%d",adxl_data);
// light=4;
// adxl_data=0X08;
SysCtlDelay(g_ui32SysClock/ (30 * 3));
ADXL345Write(&g_sADXL345Inst,0X2D, adxl_data, 1,ISL29023AppCallback, &g_sADXL345Inst);
ISL29023AppI2CWait(__FILE__, __LINE__);
ROM_SysCtlDelay(g_ui32SysClock / (30 * 3));
}
I2C_read()
{
g_vui8DataFlag = 0;
SysCtlDelay(g_ui32SysClock/ (30 * 3));
ADXL345DataRead1(&g_sADXL345Inst, ISL29023AppCallback, &g_sADXL345Inst);
ISL29023AppI2CWait(__FILE__, __LINE__);
ROM_SysCtlDelay(g_ui32SysClock / (30 * 3));
}
//----------------------------------------------------------------ADXL345.c-----------------------------------------
#define ADXL345_STATE_IDLE 0
#define ADXL345_STATE_INIT 1
#define ADXL345_STATE_READ 2
#define ADXL345_STATE_WRITE 3
#define ADXL345_STATE_RMW 4
**********************************************************************
uint_fast8_t
ADXL345Init(tADXL345 *psInst, tI2CMInstance *psI2CInst, uint_fast8_t ui8I2CAddr,
tSensorCallback *pfnCallback, void *pvCallbackData)
{
//
// Initialize the ADXL345 instance structure
//
psInst->psI2CInst = psI2CInst;
psInst->ui8Addr = ui8I2CAddr;
psInst->ui8State = ADXL345_STATE_INIT;
//
// Save the callback information.
//
psInst->pfnCallback = pfnCallback;
psInst->pvCallbackData = pvCallbackData;
//
// Write the configuration register to its default value.
//
psInst->pui8Data[0] = 0X31;
psInst->pui8Data[1] = 0x01;
//
// Write the reset bit and issue a callback when finished.
//
if(I2CMWrite(psInst->psI2CInst, ui8I2CAddr, psInst->pui8Data, 2,
ADXL345Callback, psInst) == 0)
{
//
// I2CMWrite failed so reset ADXL345 state and return zero to indicate
// failure.
//
psInst->ui8State = ADXL345_STATE_IDLE;
return(0);
}
//
// Success
//
return(1);
}
******************************************************************************************
uint_fast8_t
ADXL345Write(tADXL345 *psInst, uint_fast8_t ui8Reg, const uint16_t *pui16Data,
uint_fast16_t ui16Count, tSensorCallback *pfnCallback,
void *pvCallbackData)
{
//
// Return a failure if the ADXL345 driver is not idle (in other words, there
// is already an outstanding request to the ADXL345).
//
if(psInst->ui8State != ADXL345_STATE_IDLE)
{
return(0);
}
//
// Save the callback information.
//
psInst->pfnCallback = pfnCallback;
psInst->pvCallbackData = pvCallbackData;
//
// Move the state machine to the wait for write state.
//
psInst->ui8State = ADXL345_STATE_WRITE;
//
// Write the requested registers to the ADXL345.
//
if(ui8Reg == 0X2D)
{
//
// The configuration register is only one byte, so only a single byte
// write is necessary and no endian swapping is required.
//
psInst->uCommand.pui8Buffer[0] = ui8Reg;
psInst->uCommand.pui8Buffer[1] = *pui16Data & 0xff;
if(I2CMWrite(psInst->psI2CInst, psInst->ui8Addr,
psInst->uCommand.pui8Buffer, 2, ADXL345Callback,
psInst) == 0)
{
//
// The I2C write failed, so move to the idle state and return a
// failure.
//
psInst->ui8State = ADXL345_STATE_IDLE;
return(0);
}
}
else
{
//
// This is one of the temperature registers, which are 16-bit
// big-endian registers.
//
if(I2CMWrite16BE(&(psInst->uCommand.sWriteState), psInst->psI2CInst,
psInst->ui8Addr, ui8Reg, pui16Data, ui16Count,
ADXL345Callback, psInst) == 0)
{
//
// The I2C write failed, so move to the idle state and return a
// failure.
//
psInst->ui8State = ADXL345_STATE_IDLE;
return(0);
}
}
//
// Success.
//
return(1);
}
************************************************************************************
uint_fast8_t
ADXL345DataRead(tADXL345 *psInst, tSensorCallback *pfnCallback,
void *pvCallbackData)
{
uint8_t adxl_addr,adxl_coun;
//
// Return a failure if the ADXL345 driver is not idle (in other words, there
// is already an outstanding request to the ADXL345).
//
if(psInst->ui8State != ADXL345_STATE_IDLE)
{
return(0);
}
//
// Save the callback information.
//
psInst->pfnCallback = pfnCallback;
psInst->pvCallbackData = pvCallbackData;
//
// Move the state machine to the wait for data read state.
//
psInst->ui8State = ADXL345_STATE_READ;
//
// Read the temperature data from the ADXL345.
//
if(ADXL345_FLAG==0){
adxl_addr=0X00;
adxl_coun=2;
}
else if(ADXL345_FLAG==1){
adxl_addr=0X2D;
adxl_coun=2;
}
psInst->uCommand.pui8Buffer[0] = adxl_addr;
if(I2CMRead(psInst->psI2CInst, psInst->ui8Addr,
psInst->uCommand.pui8Buffer, 1, psInst->pui8Data,adxl_coun,
ADXL345Callback, psInst) == 0)
{
//
// The I2C read failed, so move to the idle state and return a failure.
//
psInst->ui8State = ADXL345_STATE_IDLE;
return(0);
}
//
// Success.
//
return(1);
}
******************************************************************************************
uint_fast8_t
ADXL345DataRead1(tADXL345 *psInst, tSensorCallback *pfnCallback,
void *pvCallbackData)
{
//
// Return a failure if the ADXL345 driver is not idle (in other words, there
// is already an outstanding request to the ADXL345).
//
if(psInst->ui8State != ADXL345_STATE_IDLE)
{
return(0);
}
//
// Save the callback information.
//
psInst->pfnCallback = pfnCallback;
psInst->pvCallbackData = pvCallbackData;
//
// Move the state machine to the wait for data read state.
//
psInst->ui8State = ADXL345_STATE_READ;
//
// Read the temperature data from the ADXL345.
//
psInst->uCommand.pui8Buffer[0] = 0X34;
if(I2CMRead(psInst->psI2CInst, psInst->ui8Addr,
psInst->uCommand.pui8Buffer, 1, psInst->pui8Data,6,
ADXL345Callback, psInst) == 0)
{
//
// The I2C read failed, so move to the idle state and return a failure.
//
psInst->ui8State = ADXL345_STATE_IDLE;
return(0);
}
//
// Success.
//
return(1);
}