HitTive
Newbie level 3
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:
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
}