我需要让 Adafruit 的 BNO055绝对方向模块与 MSP430 (MSP430F5529) Launchpad 协同工作。 目前、我在 I2C 方面遇到了一些问题:
如果我进入、它看起来会进入初始化状态并正确读取器件 ID 0xA0。 但是、如果我只是运行它、它似乎会卡在某个位置。 我猜这与 I2C 通信时序有关。 我 尝试在其中插入延迟、但仍然有相同的问题。 以下是我的 I2C 帮助程序函数:
void i2cSendStartTx (void){ //在发送模式下发送起始条件。 UCB1CTL1 |= UCTR | UCTXSTT; //等待 START 条件被发送并准备好发送中断。 while (((UCB1CTL1 & UCTXSTT)&&(!(UCB1IFG & UCTXIFG))); } void i2cSendStartRx (void){ //在接收模式下发送起始条件。 UCB1CTL1 &=~UCTR; UCB1CTL1 |= UCTXSTT; //等待开始条件被发送。 while (UCB1CTL1 & UCTXSTT); } void i2cSendStop (void){ //发送停止条件 UCB1CTL1 |= UCTXSTP; } void i2cWrite (uint8_t data){ //写入 TX buf。 UCB1TXBUF =数据; //轮询发送中断标志。 while (!(UCB1IFG & UCTXIFG)); } uint8_t i2cRead (void){ //等待,直到有要读取的内容。 while (!(UCB1IFG & UCRXIFG)); 返回 UCB1RXBUF; }
下面是我的 BNO055函数:
void bno055WriteReg (uint8_t reg、uint8_t data){ i2cSendStartTx(); i2cWrite (reg); i2cWrite (data); i2cSendStop(); //__delay_cycles (5000); } uint8_t bno055ReadReg (uint8_t reg){ uint8_t val = 0; //发送要读取的寄存器的地址。 i2cSendStartTx(); i2cWrite (reg); //立即读取值。 i2cSendStartRx(); //读取前发送 STOP,因为我们只读取一个字节。 i2cSendStop(); Val = i2cRead (); 返回 val; } void bno055SetMode (uint8_t 模式){ bno055WriteReg (BNO055_OPR_MODE_ADDR、MODE); //_DELAY_CYCLES (5000); } void bno055Init (void){ i2cInit (BNO055_address_a); //设置模式以更改配置。 bno055SetMode (operation_mode_config); //重置电路板。 bno055WriteReg (BNO055_SYS_TRIGGER_ADDR、0x20); //确保已启动。 while (bno055ReadReg (BNO055_CHIP_ID_ADDR)!= BNO055_ID); //_ delay_cycles (5000); //现在电路板已启动,设置为正常的电源模式。 bno055WriteReg (BNO055_PWR_MODE_ADDR、POWER_MODE_NORMAL); //_DELAY_CYCLES (2000); //现在要更改为操作模式 AMG,请更改页 ID bno055WriteReg (BNO055_PAGE_ID_ADDR、0); //_ delay_cycles (2000); bno055SetMode (operation_mode_AMG); //_delay_cycles (2000); }
有人能告诉我我出了什么问题吗?





