让 MPU6050 退出睡眠模式没有成功。我知道需要清除 SLEEP 位(位 6),但在执行清除后读取电源管理寄存器会返回 0x40。即第 6 位尚未被清除。
是的,这是一个作业,因此我们不允许使用任何图书馆等。我的导师无法提供帮助,并建议我在这里提问。
我的 I2C 设置如下
void I2C1_Setup(void)
{
//Setup I2C 1 on PORT A Pins 6, 7
// GPIO A
SYSCTL_RCGCGPIO |= (1<<0); while ((SYSCTL_PRGPIO & (1<<0)) != (1<<0)) {}
GPIOA_AFSEL |= (1<<6)|(1<<7);
GPIOA_PCTL &= ~(0xFF<<24);
GPIOA_PCTL |= (3<<28)|(3<<24);
GPIOA_DEN |= (1<<6)|(1<<7);
GPIOA_ODR |= (1<<7);
// I2C 1
SYSCTL_RCGCI2C |= (1<<1); while ((SYSCTL_PRI2C & (1<<1)) != (1<<1)) {}
/*
TPR = (System Clock/(2*(SCL_LP + SCL_HP)*SCL_CLK))-1;
TPR = (16MHz/(2*(6+4)*100000))-1;
TPR = 7
*/
I2C1_MCR = (1<<4); //master mode
I2C1_MTPR = (7<<0); //100Kbps
//Disable SLEEP mode
I2C1_MSA = 0xD0; // Set slave address and write mode
I2C1_MDR = 0x6B; // Power management register
I2C1_MCS = 0x3; // start run mode
while ( !((I2C1_MCS & 1) != 0) ) {}
while ( (I2C1_MCS & 1) == 0 ) {} // poll busy
I2C1_MDR = 0;
I2C1_MCS = 0x7; // stop start run mode
while ( !((I2C1_MCS & 1) != 0) ) {}
while ( (I2C1_MCS & 1) == 0 ) {} // poll busy
}
测试电源管理寄存器的值是使用
I2C1_MSA = 0xD0; // transmit mode
I2C1_MDR = 0x6B; // register address
I2C1_MCS = 3; // start run mode
while ( !((I2C1_MCS & 1) != 0) ) {}
while ( (I2C1_MCS & 1) != 0 ) {} // poll busy
I2C1_MSA = 0xD1; // receive mode
I2C1_MCS = 7; // stop start run mode
while ( !((I2C1_MCS & 1) != 0) ) {}
while ( (I2C1_MCS & 1) != 0 ) {} // poll busy
int data;
data = I2C1_MDR;
其返回值为 0x40。当我执行相同的步骤检查 WHO_AM_I 寄存器 (0x75) 时,确认从地址为 0x68。
我知道 MPU 正常运行,因为我们能够使用此处提供的简单草图(https://playground.arduino.cc/Main/MPU-6050)在 arduino 上获得读数
我正在使用 TM4C123GH6PM 和 keil uvision5。
真的不确定这里出了什么问题。
任何帮助表示赞赏。