Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 17:629b2f317d0a, committed 2019-12-17
- Comitter:
- Arithemetica
- Date:
- Tue Dec 17 14:30:08 2019 +0000
- Parent:
- 16:6583ad08d0d0
- Child:
- 18:07e990a9a3ed
- Commit message:
- fix the jitter in the singal due to the frequency of spi clock is too high
Changed in this revision
| imu_driver.hpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/imu_driver.hpp Tue Dec 03 14:38:15 2019 +0000
+++ b/imu_driver.hpp Tue Dec 17 14:30:08 2019 +0000
@@ -16,6 +16,9 @@
ImuExtiRcvAhrsMsg = 0b10
} ImuExtiConfig;
+/**
+ * @brief ImuDriverStatus
+ */
typedef enum ImuDriverStatus {
ImuDriverStatusOK,
ImuDriverStatusDataNotReady,
@@ -78,7 +81,7 @@
* - Data frame: 16 bits
* - CPOL: High (1)
* - CPHA: 2 Edge (1)
- * - Frequency: 1.40625 MHz (Baudrate prescaler 32 for NUCLEO-F446RE under 180MHz)
+ * - Frequency: 1 MHz (Default frequency of spi)
* - Endian: MSB first (Mbed only support MSB AFAIK)
*
* According to <A HREF="https://openimu.readthedocs.io/en/latest/software/SPImessaging.html">openIMU300ZI SPI framework</A>:
@@ -106,14 +109,11 @@
* int main()
* {
* // SPI instance, reset, data ready, slave select
- * ImuDriver<spi3, PA_10, PA_8, PA_9> imu;
+ * ImuDriver<spi3, PA_10, PA_8, PA_9> imu(ImuExtiRcvNormalMsg);
*
* while(true)
* {
- * if (imu.receiveBurstMsg() == ImuDriverStatusOK)
- * {
- * pc.printf("%.3f, %.3f, %.3f\n\r", imu.imuProcessedData.rate[0], imu.imuProcessedData.rate[1], imu.imuProcessedData.rate[2]);
- * }
+ * pc.printf("%.3f, %.3f, %.3f\n\r", imu.imuProcessedData.rate[0], imu.imuProcessedData.rate[1], imu.imuProcessedData.rate[2]);
* }
* }
*
@@ -279,6 +279,7 @@
}
++data_rcved;
+
}
data_rcved = 0U;
@@ -325,10 +326,11 @@
if (t_exti_config != ImuExtiRcvNotUsed) {
m_drdyExti.fall(this, &ImuDriver<Spi, rst, drdy, ss>::m_dataReadyExtiCallback);
+ m_drdyExti.enable_irq();
}
m_spi.format(16, 3);
- m_spi.frequency(1406250);
+ m_spi.frequency();
}
/**
@@ -358,9 +360,25 @@
return (m_extiConfig & ImuExtiRcvAhrsMsg ? ImuDriverStatusInvalidCall : receiveAhrsMsgImpl());
}
- ImuDriverStatus configExti(const ImuExtiConfig t_exti_config)
+ /**
+ * @brief This function handles the external interrupt option, whether receive AHRS
+ * burst message or normal imu message.
+ *
+ * @return ImuDriverStatus to indicate the result of the receive operation
+ *
+ * @note Never try receiving two messages at the same time
+ */
+ ImuDriverStatus configExti(const ImuExtiConfig t_exti_config) const
{
m_extiConfig = t_exti_config;
+
+ if (m_extoConfig == ImuExtiRcvNotUsed) {
+ m_drdyExti.disable_irq();
+ } else {
+ m_drdyExti.enable_irq();
+ }
+
+ return ImuDriverStatusOK;
}
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Dec 17 14:30:08 2019 +0000
@@ -0,0 +1,17 @@
+#include "imu_driver.hpp"
+
+SPI spi2(PB_15, PB_14, PB_13); //1Mbps default, MOSI MISO SCLK, forIMU
+Serial pc(USBTX, USBRX, 115200); // print debug message
+
+int main()
+{
+ ImuDriver<spi2, PC_4, PB_2, PB_1> imu(ImuExtiRcvAhrsMsg); //SPI instance, reset, data ready, slave select
+
+ pc.printf("start\n\r");
+
+ while(true) {
+// wait_ms(10);
+// pc.printf("%d\n\r", imu.imuRawData.status);
+ pc.printf("% .3f, % .3f, % .3f\n\r", imu.ahrsProcessedData.attitude[0], imu.ahrsProcessedData.attitude[1], imu.ahrsProcessedData.attitude[2]);
+ }
+}