过节吃完饭,回来继续测试板载传感器。本次测试ISM330DHCX,3轴加速度+3轴陀螺仪传感器,读Datasheet发现,是带嵌入式机器学习内核的,这部分还没有测试,趁这会先把基本功能测试一下。读完datasheet,了解个大概,看原理图,如图1所示:
2 |: [, m8 |: U7 z
: l% Z5 E) s }9 w1 g/ {- ]. C6 A
: W2 M" j/ ]1 K图1
9 G. @) `1 t& C8 c依然使用的SPI接口,根据前面的IC测试,思路搬过来使用。依然使用CubeMx现把框架搭一下,引脚定义如图2所示:3 S$ U( s* t/ T+ P# P
# f' [6 |6 k1 F$ q" Z T- L9 a
, E3 ~& A3 Z0 X+ |
图2
4 k2 y" {' o1 d1 Q1 ?# f下面就是添加所需要的初始化代码,IC初始化如下:
8 C7 h% s2 A" }) [- /* Start device configuration. */+ y2 X0 s7 q8 w
- ism330dhcx_device_conf_set(&dev_ctx, PROPERTY_ENABLE);# V1 O. M9 e! P" C
- /* Enable Block Data Update */
2 r3 R2 L" E0 e8 S' Y( p - ism330dhcx_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);, U! @" V8 M* x1 D _1 h5 O. G4 c: w; i
- /* Set Output Data Rate */
0 c4 p4 R5 B6 j; w r# \( k5 j - ism330dhcx_xl_data_rate_set(&dev_ctx, ISM330DHCX_XL_ODR_12Hz5);' P7 A% R$ G# I F* ~7 `4 y$ ]
- ism330dhcx_gy_data_rate_set(&dev_ctx, ISM330DHCX_GY_ODR_12Hz5);
9 q I# ]9 V! P% @ - /* Set full scale */# a; u; k& v( ~8 ?; @- z' K0 \% k
- ism330dhcx_xl_full_scale_set(&dev_ctx, ISM330DHCX_2g);8 F/ l' \( W0 p! H
- ism330dhcx_gy_full_scale_set(&dev_ctx, ISM330DHCX_2000dps);
3 u3 _$ t9 d4 d6 L' o" D - /* Configure filtering chain(No aux interface)9 p: b* Z: E% X o4 R) T2 Y+ g
- *# m8 I6 U* a& v4 r+ F
- * Accelerometer - LPF1 + LPF2 path
2 c2 D; C Y4 b2 K% C' { - */
4 |1 e' Y& D$ A - ism330dhcx_xl_hp_path_on_out_set(&dev_ctx, ISM330DHCX_LP_ODR_DIV_100);
1 X6 ~. @; `' S' L: ] - ism330dhcx_xl_filter_lp2_set(&dev_ctx, PROPERTY_ENABLE);
复制代码
( X$ k% V5 f+ l! w. s9 e& C在while中添加读取数据的code,如下所示:# V: n2 X( f% ], c
- ism330dhcx_xl_flag_data_ready_get(&dev_ctx, &dreg);2 w- }% M) K, P/ g; x/ X
- if(dreg)! \5 i9 N8 X6 r! n" B4 V
- {
3 V2 {& J: m4 g: D) z0 L; m* c - /* Read acceleration field data */
/ ]! Y+ l* F; |) ?$ W) s4 m - memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));3 s6 P# V5 A, z2 u
- ism330dhcx_acceleration_raw_get(&dev_ctx, data_raw_acceleration);
/ F3 c/ D$ ^, Q( I) Q7 ?" s - acceleration_mg[0] =
- E6 f$ [) R# X) T M1 a - ism330dhcx_from_fs2g_to_mg(data_raw_acceleration[0]);
( F5 }0 k, S1 ^' j+ F; r - acceleration_mg[1] =; w2 ]1 ~( B" z! U5 E
- ism330dhcx_from_fs2g_to_mg(data_raw_acceleration[1]);' i9 W8 L+ c0 d( ?8 V; f
- acceleration_mg[2] =8 a, S% k* W+ ]9 L+ J& b4 t, O
- ism330dhcx_from_fs2g_to_mg(data_raw_acceleration[2]);5 X( a7 A1 O! P$ _4 D6 J5 Z, Y
- }& ~" P8 K* o( ^$ k
- ism330dhcx_gy_flag_data_ready_get(&dev_ctx, &dreg);
* I1 l4 M6 X2 I1 V- Z( |' Y8 ?* p" R4 Y+ V - * b, C2 \/ P1 n a, P1 V
- if (dreg) {$ E' ~) ~! y) d* j% j8 U
- /* Read angular rate field data */9 s7 j1 a5 v5 h& J7 ?
- memset(data_raw_angular_rate, 0x00, 3 * sizeof(int16_t));
: U; V- |& A; N/ O - ism330dhcx_angular_rate_raw_get(&dev_ctx, data_raw_angular_rate);
9 }0 M/ n, x6 U6 E& y/ X! d/ A+ Q7 M - angular_rate_mdps[0] =
2 f, N+ a6 |7 a/ S1 t+ ~$ ?/ n - ism330dhcx_from_fs2000dps_to_mdps(data_raw_angular_rate[0]);
1 ~) g: t* C2 t' }6 [5 c$ B) E - angular_rate_mdps[1] =
) \/ U: U* }$ b - ism330dhcx_from_fs2000dps_to_mdps(data_raw_angular_rate[1]);- q% H$ s+ b9 G5 S
- angular_rate_mdps[2] =
$ O' y$ l; D, w: P: S! V" L - ism330dhcx_from_fs2000dps_to_mdps(data_raw_angular_rate[2]);
6 d6 P1 m+ w9 w" s& {, ^4 { - / Z4 K8 ?6 T1 @1 o
- }
: M1 t v" p5 z& Y' G1 J
5 Z+ G+ P! k: k" d% \4 M* h- ism330dhcx_temp_flag_data_ready_get(&dev_ctx, &dreg);, ]+ \3 ~4 W) g( v) c% i5 Z$ Z
- . g8 ~) {+ W* l/ t
- if (dreg) {4 C: u) h: _/ S; C
- /* Read temperature data */( X% Z7 }* D9 B3 F
- memset(&data_raw_temperature, 0x00, sizeof(int16_t));; M, a5 c8 E, P2 w8 L1 |$ ~
- ism330dhcx_temperature_raw_get(&dev_ctx, &data_raw_temperature);
# ?0 z6 L5 L# F l - temperature_degC = ism330dhcx_from_lsb_to_celsius(9 |0 N/ k: l" F0 g+ L" F
- data_raw_temperature);
8 {: y- f5 I9 u6 \" r; n' w) `
( P( r4 L3 ~6 D5 L+ e* p/ F2 G- }
复制代码
4 j0 D; F6 g3 `, w: W+ n6 [7 r/ L8 X( ~% A; M9 Q
1 y* f. l+ `0 ^. A- S. v1 S. F测试失败,显示hardware_fault,硬件错误。想了想,是晚上有点恍惚,把时钟配置错了,板载的外部时钟是16M,而cubemx中的默认时钟是8M,修改过来,重新生成项目,debug,测试结果如下;: t& o7 g4 z. m: \- |
7 \9 x4 @. \" d0 E% @8 e
! T% ?: f3 Q/ {1 V% _
图3
, p3 ^* R/ Y8 W2 x( U2 j5 K6 ]! S9 w
' R0 v# a8 O) J: B- A+ Y' L5 j这段时间总是感觉知识浮于基础,得往深处继续挖掘学习。下次试一试Nano edge AI。
) t% c$ W; I. ~9 |! L8 m9 F% W1 W+ [' T3 U$ x4 o% ]( b6 O0 e
|
属实可以,等楼主- A/ b U! T8 c. h, U
论坛有分享Nano edge AI 使用教程的可参考,https://shequ.stmicroelectronics.cn/thread-636670-1-1.html
这个帖子之前看过,写的不错
加油
哈哈,稍等片刻。
必须更新!