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] stm32f103c8t6 - I2C - Program stop when check ADDR

Status
Not open for further replies.

HitTive

Newbie level 3
Joined
Oct 12, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
Hello,
I have a issue with start I2C. When I check a ADDR like this : ((I2C1->SR1&I2C_SR1_ADDR)==0); program is stop.
Then in SR1 register AF bit is set,
in SR2 register MSL and BUSY bit is set.

My code:
Code:
void I2C_Setup (void) {

RCC->APB2ENR |= RCC_APB2ENR_IOPBEN ;
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;

GPIOB->CRL=0x00000000;
GPIOB->CRL |= GPIO_CRL_MODE6| GPIO_CRL_MODE7;
GPIOB->CRL |= GPIO_CRL_CNF6| GPIO_CRL_CNF7;

I2C1->CR1|= I2C_CR1_SWRST;
I2C1->CR1&=~I2C_CR1_SWRST;

I2C1->CR2 = 0x08; // Freq 8 MHz
I2C1->CCR = 0x28; //40// (8MHz / 2/ 40 =100k)
I2C1->TRISE = 9; // limit slope

I2C1->CR1 |= I2C_CR1_PE;
}

_______________________________________________________________
------------------------------------------------------------------------

void I2C_Send()
{
int length=8;
uint32_t dummy;

I2C1->CR1|=I2C_CR1_START;// request a start
while ((I2C1->SR1&I2C_SR1_SB)==0 ); // wait for start to finish
dummy = I2C1->SR1; // read of SR1 clears the flag
I2C1->DR = 0x27; // transfer address
while ((I2C1->SR1&I2C_SR1_ADDR)==0); //<- w tym miejscu program stoi
dummy = I2C1->SR1; // clear the flag
dummy = I2C1->SR2;

while (length--)	// transfer whole block
{
while ((I2C1->SR1&I2C_SR1_TXE));// wait for DR empty
I2C1->DR = 0b0; // trsnsfer one byte, increment pointer
}


while (I2C1->SR1&I2C_SR1_TXE || I2C1->SR1&I2C_SR1_BTF); // wait for bus not-busy
I2C1->SR1|=I2C_CR1_STOP; //request a stop
}
 

Hi,

Why did you use semicolon after while. are you using "while ((I2C1->SR1&I2C_SR1_SB)==0 ); // wait for start to finish" as a function?


Please clarify. Also please check for I2C line you have proper pullups resistors in hardware.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top