本文整理汇总了C++中USART::Receive方法的典型用法代码示例。如果您正苦于以下问题:C++ USART::Receive方法的具体用法?C++ USART::Receive怎么用?C++ USART::Receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类USART
的用法示例。
在下文中一共展示了USART::Receive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void Run(uint32_t i2cClockSpeed)
{
bool dmpReady = false; // set true if DMP init was successful
uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount; // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer
Quaternion q; // [w, x, y, z] quaternion container
VectorInt16 aa; // [x, y, z] accel sensor measurements
VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
VectorFloat gravity; // [x, y, z] gravity vector
float eu[3]; // [psi, theta, phi] Euler angle container
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
uint16_t y, p, r;
float yaw_offset;
I2C1* i2c = GPIO_Helper::SetupI2C1_PB_6_9(i2cClockSpeed);
i2c->SetErrorHandler(this);
MPU6050 mpu(i2c);
//Initialized with highest sensitivities
mpu.reset();
RCC_Delay_ms(50);
mpu.initialize();
#ifdef USE_USART
uint32_t clockSpeed = 1200000;
USART* usart = GPIO_Helper::SetupUSART2_PA_2_3(clockSpeed);
#endif
devStatus = mpu.dmpInitialize();
if (devStatus != 0)
{
while (1)
;
}
mpu.setDMPEnabled(true);
packetSize = mpu.dmpGetFIFOPacketSize();
while (1)
{
// wait for MPU interrupt or extra packet(s) available
//while (!mpuInterrupt && fifoCount < packetSize) {
//}
// reset interrupt flag and get INT_STATUS byte
mpuIntStatus = mpu.getIntStatus();
// get current FIFO count
fifoCount = mpu.getFIFOCount();
// check for overflow (this should never happen unless our code is too inefficient)
if (mpuIntStatus & 0x02)
{
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize)
fifoCount = mpu.getFIFOCount();
// read a packet from FIFO
mpu.getFIFOBytes(fifoBuffer, packetSize);
// track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;
// display quaternion values in easy matrix form: w x y z
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetEuler(eu, &q);
eu[0] *= 180. / M_PI;
eu[1] *= 180. / M_PI;
eu[2] *= 180. / M_PI;
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
//rad to degrees
ypr[0] *= 180. / M_PI;
ypr[1] *= 180. / M_PI;
ypr[2] *= 180. / M_PI;
// display real acceleration, adjusted to remove gravity
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
// display initial world-frame acceleration, adjusted to remove gravity
// and rotated based on known orientation from quaternion
mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
#ifdef USE_USART
if (usart->IsRXNE())
{
if (usart->Receive() == 23)
{
usart->SendWord((int16_t)(ypr[0]));
usart->SendWord((int16_t) ypr[1]);
usart->SendWord((int16_t) ypr[2]);
}
}
//.........这里部分代码省略.........