Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] STM32f103 interfacing with adxl345 via i2c

Status
Not open for further replies.

vimalraj

Junior Member level 2
Joined
Apr 3, 2019
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
196
I am working on interfacing ADXL345 accelerometer with stm32f103 blue pill board through I2C communication. I have written the code in keil software by surfing the internet which works fine sometimes, verified using logic analyzer. address acknowledged.png

The problem is sometimes the BUSY bit is set after starting communication. I do not know why this arises.
after searching related to this problem I found that the I2C clock must be enabled before configuring gpio to alternate functions. but the problem is not solved
I stuck with this Busy bit.

any ideas are welcome

thank you.
 
Last edited:

Hi,

Which BUSY bit? STM32 or ADXL?
Then look into the according datasheet and application note (if exist).

At least this is how I´d do it.

Klaus
 

i2c on f103 is a pure pain. Even in commercial projects i'm using sw i2c implementation. Thanks god, it has bitbang
 

Hi,

Which BUSY bit? STM32 or ADXL?
Then look into the according datasheet and application note (if exist).

At least this is how I´d do it.

Klaus
It is stm32 busy bit.
I have referred to the datasheet it says that busy bit is set if scl or sda line is low.

I don't know why is it happening at the beginning of the communication.

- - - Updated - - -

i2c on f103 is a pure pain. Even in commercial projects i'm using sw i2c implementation. Thanks god, it has bitbang

Are you using sw i2c for STM32F103?
If yes, can you name it.
 

Hi,

It is stm32 busy bit.
I have referred to the datasheet it says that busy bit is set if scl or sda line is low.

I don't know why is it happening at the beginning of the communication.
I'm not experienced with STM hardware I2C .... easyrider surely has the experience.

Thus I just try to further analyze your given informations:

So, the busy bit says SCL is low.
My questions:
* measure the SCL state. What's the real state? Mind: Check if the measurement does not influence the busy bit state.
* did you install external pullup resistors?
* is your port setup correct?

Klaus
 

I wrote my own sw i2c lib long time ago and using it in many projects. It is simple, you can do that easily.
 

Code:
// Alternate function config.
	GPIOB->CRL = 0xFF000000;
	// Peripheral clk enable
	RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
	
// I2c peripheral enable
	RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;
	
	
	I2C1->CR1 = 0x0000;									//	Peripheral disable
	
	// I2c clk config.
	I2C1->CR2  = 0x0008;										//	Freq  0b001000  8MHz 
	I2C1->CCR  = 0x28;												//	clk config.			
	I2C1->TRISE = 0x09;										//	max. rise time
	
	I2C1->CR1 |= I2C_CR1_PE;								//	Peripheral enable	
	
	// starting commmunication
	I2C1->CR1 |= (1<<8);	//	start bit
	while (!(I2C1->SR1 & 0x0001));
	a=1;
	
	// sending slave address with write command
	I2C1->DR = 0xA6;											//	Device address with read bit
	while(!(I2C1->SR1 & 0x0002) );
	read_status = (I2C1->SR2);

	
	// Sending register address
	I2C1->DR = 0x2C;												//	Device internal register address
	while (!(I2C1->SR1 & (1<<7)));						// 	wait for TXE bit set
	
	// restarting communication before reading data
	I2C1->CR1 |= (1<<8);										// 	Restart
	while(!(I2C1->SR1 & 0x0001));
	
	//	Sending slave address with read command
	I2C1->DR = 0xA7;
	while(I2C1->SR1 & 0x0002);
	read_status = (I2C1->SR2);
	
	I2C1->CR1 &= ~0x0400;
	// wait until data recieve and read from DR register
	while (!(I2C1->SR1 & 0x0040));
	data = I2C1->DR;
	
	// stop communication
	I2C1->CR1 |= (1<<9);
	while(!(I2C1->SR2 & 0x0002));

i was busy with another work that's why late reply.
the code i have uploaded is what i have written to try I2C i could not find any mistake in it if someone can spot it, will help me to proceed.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top