2017-09-08 10:18 PM
2017-09-12 04:50 AM
Why i2c data reception cannot be achieved from rtc in stm32f446. I can write data to rtc. I tried to receive data using hal driver but then also data reception doesn't occurs.
HAL_I2C_Master_Receive(&hi2c2, 0xDF, data_read, 3, 1000);
2017-09-12 09:18 AM
Use 0xDE, and let the downstream code set the R/W bit
I2C2->DR |= 0XDE; // What the heck? Just write the register, don't OR it
I2C2->DR |= 0x00; // Ok, this does what?
Register level programming requires some grasp of what is going on
2017-09-13 08:11 AM
Thank you sir for your reply . I got the code for i2c write operation when i enabled gpio output type as open drain and when OR operation removed .But i couldn't read
data from rtc .Always data shows 0 .
void i2c_start()
{ while(I2C2->SR2 & (1<<1)); // wait until I2C1 is not busy anymore I2C2->CR1 |= (1<<0); // Peripheral enable I2C2->CR1 &= ~(1<<11); // Disable POS I2C2->CR1 |= (I2C_CR1_START); // Send I2C1 START condition while(!((I2C2->SR1 & I2C_SR1_SB) && (I2C2->SR2 & 0x03))); // wait for I2C1 EV5 (check start condition,bus busy,master mode) I2C2->DR = 0XDE; // slave address while(!((I2C2->SR1 & 0X82) && (I2C2->SR2 & 0x07))); // wait for I2C1 EV6 (check address sent,data bytes transmitted,bus busy,master mode)}void i2c_write()
{ I2C2->DR = 0x00; while(!((I2C2->SR1 & 0x84) && (I2C2->SR2 & 0x07))); // check data register empty,data byte transfer succeeded}
void i2c_restart()
{ I2C2->CR1 |= (I2C_CR1_START); // Send I2C1 START condition while(!((I2C2->SR1 & I2C_SR1_SB) && (I2C2->SR2 & 0x03))); // wait for I2C1 EV5 (check start condition,bus busy,master mode) I2C2->DR = 0XDF; // slave address I2C2->SR1 &= ~(1<<10); // Acknowledge disable while(!((I2C2->SR1 & I2C_SR1_ADDR) && (I2C2->SR2 & 0x07))); //wait for I2C1 EV6 (check address sent,data bytes transmitted,bus busy,master mode)}void i2c_stop(){ I2C2->CR1 |= (I2C_CR1_STOP);}void i2c_read(){ while((I2C1->SR1 & I2C_SR1_RXNE)); data = I2C1->DR;}2017-09-13 11:25 PM
Sorry , ...
void i2c_read()
{ while(!(I2C1->SR1 & I2C_SR1_RXNE)); data = I2C1->DR;}waiting on while(!(I2C1->SR1 & I2C_SR1_RXNE));