2019-09-13 12:49 AM
Hi.
I am trying to communicate with MPU6050 through I2C protocol. I am using STM32f103VE.
The problem I have, is that after start condition and transmitting slave address and slave internal register address, and then starting again,this time with slave address in 'read mode' (based on manual) ,the sensor wont respond and keeps both scl and sda low.
At first I thought there was a problem with the sensor so I bought a new one but still it wouldn't work!!
I appreciate it if someone could help me.
Thanks in advance.
Here is my code:
#include "stm32f10x.h"
void I2C_Init(void){
RCC->APB2ENR|=RCC_APB2ENR_AFIOEN;
RCC->APB2ENR |=RCC_APB2ENR_IOPBEN ; //portB clock enabled
RCC->APB1ENR|=RCC_APB1ENR_I2C1EN;
GPIOB->CRL = 0xFF000000 ; // PB6,7 Alternate output Open drain
I2C1->CR2|=0x0024; //36MHz frequency
I2C1->CCR=0x00B4;// Sm enabled,100khz
I2C1->TRISE=0x24;
I2C1->CR1=(1<<10);//acknowledge enabled
I2C1->CR1|=I2C_CR1_PE;//I2C enabled
}
void I2C_interface(void){
I2C1->CR1 |=I2C_CR1_START;
while(I2C1->CR1 & I2C_CR1_START);
I2C1->DR=(0x68<<1);
while(!(I2C1->SR1 & I2C_SR1_TXE));
(void)I2C1->SR1;
(void)I2C1->SR2;
while(I2C1->SR1 & I2C_SR1_ADDR){};
I2C1->DR=(0x44);
while(!(I2C1->SR1 & I2C_SR1_TXE)){};
I2C1->CR1 |=I2C_CR1_START;
while(I2C1->CR1 & I2C_CR1_START);
I2C1->DR=((0x68<<1)|(0x01));
while(!(I2C1->SR1 & I2C_SR1_RXNE)){};
(void)I2C1->DR;
when I comment " while(!(I2C1->SR1 & I2C_SR1_RXNE)){};" , the clock keeps going but I constantly read 0 value...