cancel
Showing results for 
Search instead for 
Did you mean: 

I2C stuck at I2C_CheckEvent, ADXL345 accelerometer

wsevendays
Associate II
Posted on November 27, 2011 at 23:03

Hello. I want to setup ADXL345(SDA - PC3, SCL - PC2)

I didn't find any information about my problem in the internet.

How I init I2C:

void I2CG_Init(void)

{

    GPIO_InitTypeDef  GPIO_InitStructure;

    I2C_InitTypeDef  I2C_InitStructure;

    // GPIOB clock enable

    RCC_AHBPeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

    // I2CG clock enable

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2CG, ENABLE);

    // I2CG SDA and SCL configuration

    GPIO_InitStructure.GPIO_Pin = SCL|SDA;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Enable I2CG reset state

    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2CG, ENABLE);

    // Release I2CG from reset state

    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2CG, DISABLE);

    // I2CG configuration

    I2C_DeInit(I2CG);

    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_16_9;

    I2C_InitStructure.I2C_OwnAddress1 = 1;

    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

    I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;

    I2C_Init(I2CG, &I2C_InitStructure);

I2C_Cmd(I2CG, ENABLE);

    I2C_AcknowledgeConfig(I2CG, ENABLE);

}

This step seems to be successful.

Then I try to init ADXL345:

void ADXL_Init(void)

//Turn on

{

I2C_ByteWrite(0x00, 0x2d);

I2C_ByteWrite(0x16,

0x2d

);

I2C_ByteWrite(0x08,

0x2d

);

}

And get error checking ''

I2C_CheckEvent''//status = ERROR;

 void I2C_ByteWrite(uint8_t val, uint8_t Addr)

{

    I2C_GenerateSTART(I2CG, ENABLE); // Send START condition

    while(!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_MODE_SELECT)); // Stuck at this

    I2C_Send7bitAddress(I2CG, DEV_ADDR, I2C_Direction_Transmitter); // Send address for write

    while(!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); // Test on EV6 and clear it

    I2C_SendData(I2CG, Addr); // Send the internal address to write

    while(!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); // Test on EV8 and clear it

    I2C_SendData(I2CG, val);

    while (!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); // Test on EV8 and clear it

    I2C_GenerateSTOP(I2CG, ENABLE); // Send STOP condition

}

I'm sure that I connect wires properly.

#adxl345 #c #i2c #stm32
1 REPLY 1
emalund
Associate III
Posted on November 28, 2011 at 15:16

if this is f1xx READ THE ERRATA