I am trying to send a simple data from STM32f103 to another one. But I am having trouble with my code. I have been working on it since 2 weeks and I couldn't find any solution. I am using PROTEUS to simulate and KEIL to compile.
according to data sheet, after start event SB bit is set in SR1 register. To test this I placed this code:
while( !(I2C1->SR1 & I2C_SR1_SB) );
But it stucks inside the loop. Can someone help me please? Thank you for reading.
And Here is my main function.
int main(){
clock_init();
//GPIOB clock enable,AFIO enable
RCC -> APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPBEN;
//I2C1 clock enable
RCC -> APB1ENR |= RCC_APB1ENR_I2C1EN;
//Pin B6 , B7 alternative function open drain enable, GPIOB other CRL pins output and 50mhz
GPIOB -> CRL |= 0xff333333;
// reset the I2C1 peripheral
RCC->APB1RSTR |= RCC_APB1RSTR_I2C1RST;
RCC->APB1RSTR &=~RCC_APB1RSTR_I2C1RST;
I2C1 -> CR2 |= 0x08<<0; //8mhz freq[5:0]
I2C1 ->CCR &= ~(1<<15); //clear bit 15 to 0 (to have Standard Mode)
I2C1 ->CCR |= 0x0028;
I2C1 ->TRISE |= 0x0009;
I2C1->CR1 |= I2C_CR1_PE; //peripheral enable
I2C1->CR1 |= I2C_CR1_START; //Start bit set
while( !(I2C1->SR1 & I2C_SR1_SB) );
GPIOB -> BSRR |= 0x0000ffff;