问答
直播中

许华

10年用户 42经验值
擅长:嵌入式技术 控制/MCU
私信 关注

使用I2C读取AT24C02数据,写入数据逻辑波形不正确?

使用SDK自带的I2C去读取AT24C02过程中,使用逻辑分析仪看波形写入的数据与逻辑波形不对,写入0x55,波形显示不是写入值。谁知道怎么处理请帮忙看看我写错了吗? 1493129033128045.png ; k2 v) D4 I- B( z7 p0 h( w* C

/ p4 |% B3 |4 C# L; c9 g//////////////////I2C部分/////////////////////////////
- w! M/ L7 w. l0 K/**. }: C. H7 u' d9 ]1 C) P% E
******************************************************************************8 Y: t% p4 X' b5 B
* @file    apds9930.c+ k& u2 E# h/ _. P/ q& d
* @author  William Xu
/ ~0 g2 f( o  b, u" M' ^5 T' ~ * @version V1.0.0
9 ~* s' d- {, q * @date    17-Mar-2015
# {. P* B$ M6 h' j! n! H* C * @brief   apds9930 user controller operation$ i' d7 e' O1 y3 O7 t3 l$ H  P% J) k5 R, g
******************************************************************************' `6 U# _% u( e3 ?  f
*  UNPUBLISHED PROPRIETARY SOURCE CODE
. V& O! h" |  I7 A9 i *  Copyright (c) 2016 MXCHIP Inc.
  b  v7 p  m  i( y, P- t- B3 H *
2 i$ D; Z. f2 n* T' o6 m  F) Q *  The contents of this file may not be disclosed to third parties, copied or
8 h) L; ^( Y( \& ?. w *  duplicated in any form, in whole or in part, without the prior written3 n: n7 f& w% H9 d% q# O3 h  r  ]
*  permission of MXCHIP Corporation.+ y0 X0 d) Y5 I9 a3 L( T
******************************************************************************" ^7 C) h) `( ]; C5 \2 w& Q
*/7 o' b. l; A8 z& ~+ n( ^$ V( S

6 ?8 v# |, _; Z0 A5 \- k( _2 f
; M9 `2 x# a3 _: L
#include "mico.h"
2 }* a8 k( J6 z' k% E#include "AT24CXX.h"0 U8 q+ b' f& \! C! c2 D5 x

6 P% k( }8 B% q# i) i& i" X' G
" `& x) X) @8 Y) t4 m$ M
#define apds9930_log(M, ...) custom_log("APDS9930", M, ##__VA_ARGS__)1 F3 x& b* o$ q2 t; }8 Z7 k# l. C

* m+ g+ P  s0 n$ ~5 I! u

& Z, }! d0 j% a5 R9 Z# w) B# A4 a5 f/************** I2C/SPI buffer length ******/  ~+ m4 E: e' P9 P$ C
#define        AT24CXX_BUFFER_LEN 3
3 j- f; q- Q/ i4 M0 m( w: X: c#define AT24CXX_ID   0xA0 2 o9 d6 Z4 ^" c* i
1 u! B' E! |" q

3 j  H2 B9 Y2 [* L3 X7 S/* I2C device */
7 u" T+ g, ]. q& H4 q( p+ Emico_i2c_device_t AT24CXX_i2c_device = {
* f1 }. H) m2 N! ~  AT24CXX_I2C_DEVICE, AT24CXX_ID, I2C_ADDRESS_WIDTH_7BIT, I2C_STANDARD_SPEED_MODE
# I* [/ O9 Z& Y7 E};
) Y3 ]9 ]7 }* b2 I/ jmico_i2c_device_t AT24CXX_i2c_device0 = {+ B7 A; _7 z4 }: q& K
  AT24CXX_I2C_DEVICE, AT24CXX_ID+1, I2C_ADDRESS_WIDTH_7BIT, I2C_STANDARD_SPEED_MODE) A1 B+ s+ h4 V. }% g
};
3 K! N. H: g% \5 D9 J5 P/*************************************************8 v. M7 ?( T- c# I4 P2 G$ M
* Function:  AT24CXX_I2C写6 W9 X+ o9 M1 w/ B
* parameter:  
8 {0 M, {6 h& ^, c0 C/ |) S' H& o              uint8_t reg_addr          地址   . p& h: c+ F0 U$ |7 ]( b3 \
              uint8_t *reg_data         参数
2 `4 e4 B  ^+ j% f& h3 P& ^              uint8_t cnt               个数
% c: Y1 Z5 o2 b1 M- ` * Return  :  返回0: v- h5 h! O2 }$ ^5 u5 @$ I1 E9 W
* Modify:2 a, I: p2 r' I1 e- i" F0 C' H% e. q7 R
**************************************************/
- N/ r! \1 H  \9 G; dOSStatus AT24CXX_I2C_bus_write(uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
& w  h+ D4 @, Z' x7 G{, R' ^; m4 A- A6 c1 M
  OSStatus err = kNoErr;
; [7 `' l" ~4 j- i0 g  mico_i2c_message_t apds_i2c_msg = {NULL, NULL, 0, 0, 0, false};
6 l5 q% L* r) ~9 ?5 P, Q. ~* d2 {9 S3 E6 x) z
% _/ Y- |( S1 S
  uint8_t array[AT24CXX_BUFFER_LEN];
: z; v- O3 R4 @: e4 v( J  uint8_t stringpos;( M; M. M& _* A+ S) X
  array[0] = reg_addr;
- V- a3 I! c- ?" R9 }  for (stringpos = 0; stringpos < cnt; stringpos++) {7 ]0 C. Y& d, @& [' g" n% V1 u
          array[stringpos + 1] = *(reg_data + stringpos);% b; R" e9 H2 Y
  }. c& t# n; s; ~7 E
# o  D# q, O1 w  ~& \

% C# Z' G* @/ p  err = MicoI2cBuildTxMessage(&apds_i2c_msg, array, cnt + 1, 3);0 c3 r# X& o& i& h& X* z5 Y
  require_noerr( err, exit );+ M* f6 W7 q$ }- C7 P
  err = MicoI2cTransfer(&AT24CXX_i2c_device, &apds_i2c_msg, 1);
6 y/ y: m) t. @5 i, C  require_noerr( err, exit );$ M  D4 _. [, |3 n' [, L* `
  . V  r* Z" k0 c8 X! |$ w
exit:  / G) a/ j1 l* M8 y- S
  return err;
  [4 [1 Y  u7 Y. Q' e* i}( y8 U% f) G  M& ~2 n
/*************************************************- k- [# Q7 @4 {2 j
* Function:  AT24CXX_I2C读
; r2 X7 W6 a6 R& t9 ~' g9 H' ~* parameter:  
& b  _" g9 P- x3 b/ N1 k; ^3 t              uint8_t reg_addr          地址   " ^: H. N; W1 c3 a: M
              uint8_t *reg_data         参数  d9 d8 r5 p( c: o- u! X) i
              uint8_t cnt               个数. S$ }0 @) K: y% ?4 W, H. T  q
* Return  :  返回0
4 v! `  \; x! A! v+ F, Q * Modify:
, I4 x% C$ r1 J* k! R/ x- L**************************************************/
0 r8 Z! `. I2 T7 {' u% _OSStatus AT24CXX_I2C_bus_read(uint8_t *reg_data, uint8_t cnt)
: m) R4 j" x  N; g{
% X! F3 B  ]5 C$ }+ q  OSStatus err = kNoErr;0 c# m7 r. q4 w3 O! l. m1 T
  mico_i2c_message_t apds_i2c_msg = {NULL, NULL, 0, 0, 0, false};9 ~( a' d0 T7 v8 i! Y
2 ?8 s3 D6 v: h5 A; l2 i

% U/ ?" n( I" Y7 u! E  err = MicoI2cBuildRxMessage(&apds_i2c_msg, reg_data, cnt, 3);4 d* F3 I& W& U. e* f: \) e
  require_noerr( err, exit );
6 x6 V0 L7 C2 D  err = MicoI2cTransfer(&AT24CXX_i2c_device0, &apds_i2c_msg, 1);
7 Y7 `* P' B% u3 x0 u5 v, ~  require_noerr( err, exit );
/ b& I  N3 n% `% Y$ B& d& Q
2 c* i+ S7 C9 v
3 [0 N2 @1 [( D0 n
exit:
; a" O* |- x- y* k  return err;
  R, i! e# s1 R}3 A& a- n! u5 M8 d1 @+ z
/*************************************************4 q0 P; L5 a9 J4 c6 l) U+ F' F5 R9 E
* Function:  AT24CXX_I2C写一个字节" o& [+ j# C" s; v; S# |
* parameter:  
, w$ [3 M1 O7 c              uint8_t reg_addr          地址   5 H9 p9 @2 `+ Q' Z+ F$ F9 ^
              uint8_t reg_data         参数
* M5 {/ T8 H. }! m# z/ _% b * Return  :  返回0
# q7 d) i; S3 K) H6 b7 R7 [. |9 _ * Modify:
$ t0 i  x9 `1 w6 O9 o# Q5 ~**************************************************/& r" ^; l( H* _2 e& a
OSStatus AT24CXX_Write_RegData(uint8_t reg_addr, uint8_t reg_data)
9 V1 O  J: Y8 V4 h; I* f{/ j" G& e5 @# U1 b" ]  W- R5 U
OSStatus err = kNoErr;7 Y2 Y. l4 M# U/ X% O- w
err = AT24CXX_I2C_bus_write(reg_addr,®_data,1);
+ _3 \1 e" U7 T" {- N; G  return err;  I2 J& |& @. w. K+ ]% `% g8 L
}! o0 \  n+ R  N% [5 [3 r" m
/*************************************************  v- Q" p' w- `: `: i+ r0 h
* Function:  AT24CXX_I2C读一个字节
5 T3 R: J4 a. h5 o/ z* parameter:  
/ a3 }4 g0 P* D$ W  D4 ?9 E* R" U# Z              uint8_t reg_addr          地址   
3 J9 Q& W; u2 F9 t  G              uint8_t *reg_data         参数
4 K; z0 k; l6 N( n * Return  :  返回0# L/ p6 q0 N+ U- P3 g
* Modify:
5 u" q- C: t1 U' {) N**************************************************/
! S7 z; r4 k, K% V& EOSStatus AT24CXX_Read_RegData(uint8_t reg_addr, uint8_t *reg_data)
. g6 t/ U4 ?! w  H2 w# R{! e5 `( B1 x& u: |1 s6 w6 {5 S; W
  OSStatus err = kNoErr;2 j$ W5 p$ y$ c+ ~( {
  err = AT24CXX_I2C_bus_write(reg_addr, NULL, 0);- o7 R5 B0 G3 A2 i) Y& `/ j
  /*Should have delay time here*/
* R9 y6 E( Q8 n, |  mico_thread_msleep(5);
6 ?* a1 B  n5 l$ {/ R1 Q" K. @* q# l  err = AT24CXX_I2C_bus_read(reg_data, 1);7 @4 S- k( D. Y- S  @8 D/ C; J
  return err;  
* C  K: G% p2 a7 r9 F: j}
$ s3 |1 m6 o5 o  ?( @6 M/*************************************************
9 Z( ?  `# d* d$ N# E * Function:  AT24CXX_I2C读一个字节' F6 a9 Q/ j  ~! k& p
* parameter:  
: i! q0 J9 {  n5 T2 D. F$ J              uint8_t reg_addr          地址   3 G5 G/ e  Q* o6 e  F
              uint8_t *reg_data         参数
% J" }; v4 i- W2 S" ] * Return  :  返回0$ M' w. T1 ?8 ?* T' S9 \. _
* Modify:
' [8 g& a% K# r! M. X2 @& [6 m0 s9 h**************************************************/& P3 b0 L. E2 z( f
//OSStatus AT24CXX_Read_one(uint8_t Write_addr,uint8_t Write_Data): m% z$ E$ J$ M0 ~6 b) L1 `& a
//{
  h4 {4 H" p) t' i2 |7 D//  OSStatus err = kNoErr;7 o) ]) @- o$ p# [
//  err = AT24CXX_Write_RegData(Write_addr,Write_Data);( f( E# _+ q! ^
// return err;
' I: |6 ]2 P- s//}: K1 P* Y, p/ s# \3 g

% z/ x! x9 E# N2 r) ?" R. \% C
# H" }5 S( L& F- Q
OSStatus AT24CXX_sensor_init(void)
2 {$ Y+ _, c1 p* T) s& a{
" K' @/ W1 ^2 ~! z" Q8 B, ?  OSStatus err = kNoErr;' O  L% U% j0 L
//  uint8_t device_id;  h! i! S- `, ]$ {7 J
  % b/ T! U" E  ?5 N
  MicoI2cFinalize(&AT24CXX_i2c_device); ! L" ]$ m. O  G
  ) l" X! |6 v: I) t6 [5 T) b% s
  /*int Si7021 sensor i2c device*/4 B4 @! {$ n) U" D
  err = MicoI2cInitialize(&AT24CXX_i2c_device);; O/ E" r  ~1 R2 K$ C+ D
  require_noerr_action( err, exit, apds9930_log("Si7021_ERROR: MicoI2cInitialize err = %d.", err) );) w+ r# |+ a% t( y
  / l# \7 K( n4 K- a. B6 I1 U( T
  if( false == MicoI2cProbeDevice(&AT24CXX_i2c_device, 5) ){
' x7 ^+ D6 N/ U- I  h+ n+ r    apds9930_log("Si7021_ERROR: no i2c device found!");
: u9 W% R# L9 v$ [    err = kNotFoundErr;
& |. V3 ^! b$ f0 j    goto exit;+ M2 l" ~6 Z4 x( {6 y1 U& N$ O
  }: S' u. k5 e0 B; c0 q. t+ e
        else7 S0 }4 x3 v/ c. o) n
        {
( Q+ \+ d5 G0 s& H! e9 _4 i3 f         apds9930_log("Catch I2C device!");8 a; u; G5 J, m* _8 H% s4 K: p
        3 n# r5 K7 V6 ^
        }  
6 T/ W1 T% J( |; }, ^exit:; Q( a+ y  W% [1 j8 G. }" n7 X
  return err;
1 S, g( x* w7 ]) O+ {0 d& m}& h* s6 C* ~* r6 D7 Q
" ^( e, {: ]% M; z  e
% {7 n8 ?9 t; Y0 x

, |4 M( U& ^6 O9 P* Z1 s9 V# \  x

6 S5 t# y5 N0 B& S, D# ?/ uOSStatus AT24CXX_sensor_deinit(void), G( |; F; b/ i6 Q# H
{
* {0 v7 [0 g+ k: q& Z) Y  OSStatus err = kUnknownErr;$ B% `0 x6 }0 w6 t& W9 N! D) b* n
  
) y; _3 q' Q4 T' A# W  err = MicoI2cFinalize(&AT24CXX_i2c_device);$ U. H7 c( J' |& |
  require_noerr_action( err, exit, apds9930_log("Si7021_ERROR: MicoI2cFinalize err = %d.", err));
1 |! {: k+ J1 L  0 `# B; ^; ~4 `1 q2 r. i* L, a
exit:8 V1 s7 \3 w, q$ j
  return err;
3 p1 l  H" I" ^: p4 y5 o}
) u8 I& d  s4 R: B8 a$ O) a//////////////调用部分/////////////////////////////
! Y, Y" i$ s: |6 `: E5 N' ~5 P) g  j6 L
1 r4 }; P- N8 _, D* F#include "mico.h"+ B7 ]' }# y' |/ F. q
#include "micokit_ext.h"4 v2 g* t( ^7 d/ W0 n
#include "json_c/json.h"( r" S. o! O# v) J- A1 I
#include "sensor/DHT11/DHT11.h" /*温湿度传感器相关头文件*/, f+ G6 i7 \4 m/ i1 P8 J  q7 G

5 a# e% f) I' z, b8 v* B5 B
2 x% o' Z" i! a* l! O$ s- v#define wifi_station_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__)
& e" W2 H) I' ]& S#define ext_rgb_led_log(M,...) custom_log("EXT", M, ##__VA_ARGS__)
& j7 A- ^: k0 Q#define COLOR_MODE RGB_MODE
. [  e3 G: k) n. T6 ^8 P2 W3 X9 W' Y' z6 ~2 L/ Y
7 a3 @. i" [" X$ N, ]
mico_thread_t t_handler = NULL;/*线程句柄*/
( l5 T: s/ r$ n5 p5 a( l; Qmico_rtc_time_t cur_time = { 0 };
* E- r' t" Y5 eunsigned char APPD = 0,SDD=25;! Y7 w, R/ s4 H6 q7 P, `
typedef struct
2 v0 t$ |$ a( Q! k2 R2 }4 F1 s{$ W5 U; W8 t% S& n
unsigned char Alarm_N;         //闹铃个数
7 A) |$ _. l+ Q+ ^ unsigned char Time_Alarm[3];) m1 Z& b% R* }+ a
unsigned char WeekDays_DATA:3;1 k( |8 c3 k3 |9 U
// unsigned char
, b' q+ |$ a: |: J" J8 T}Time_Data;8 a, z% ]' ^, L" j
typedef struct notify$ q; t: Q* k# u9 |5 W$ d$ y
{7 P! |- N5 ]6 q( h4 e) a+ D' D
  uint8_t cmd;
& ~  L" {* H' B7 U} notify;
9 c' w4 a, g! i& f4 N  b- ?5 kTime_Data Time_Run;
4 M* [0 F8 {3 G
) e: o+ W- e5 B% p' t% K" Sstatic int isMqttThreadEnter = 0;" V1 Y5 A0 i0 ?: A7 N# k
/*************************************************' G; f# O! k4 O  B2 d, Z, a( Q
* Function:  2^N计算函数
0 z' H: o( P2 f * parameter
# E5 _" l$ H  b$ S- N% z * Return          sum计算的结果* V  i9 o& `8 C( h& K! Z
* Modify:
/ R! w' Z1 P! h0 S. {1 ]  f* W**************************************************/
# Y& I3 q2 P+ J4 runsigned char Mult2(unsigned char n)) ]: |5 y  @. z; Z4 ^* Q5 [
{  F- x9 G4 Z5 [: z4 y% a
  unsigned char sum = 2,m;
8 X* a- A: o/ Y3 U" \  if(n==0) return 1;2 H- q# Q1 m/ @& q& C8 S
  for(m=1;m " q. o4 A: {7 U( i) ]  return sum;
, j- C) _& y" ]( Q+ H! I  u) D}! w; E3 s, @# v1 S8 [+ e
- T8 ?) a+ h( S: t* @
/*************************************************$ f/ G! H9 R  _. J8 k+ T4 Z% C9 q
* Function:  RTC初始化函数
4 O) `3 i# D" n% ]/ r * parameter
, _3 C9 [% H$ e * Return$ n  F3 k: W5 E, m+ v, @! Q
* Modify:
' n# X0 R. j0 w" @0 O" \**************************************************/0 o/ O% q% a7 |" M
void RTC_Time_Init(void)) p2 K3 n4 ^, e2 N5 w  ]. T
{) W6 D5 _( @# u1 S4 p
  cur_time.year = 17; //设置时间9 e- ~$ e5 t5 K# ?' n3 i& u
  cur_time.month = 3;) n* ?# _! @  ]' ~' @2 B, e1 z
  cur_time.date = 23;. K6 [! h/ m) v
  cur_time.weekday = 4;
* N! ]. h- j1 v  cur_time.hr = 23;5 N+ m9 y/ Y. |8 X: u! a
  cur_time.min = 58;
7 B# p5 L$ ?4 @+ R) V  G4 `  cur_time.sec = 0;
4 z5 Q* U, Z  C5 s' k" E4 }  Time_Run.WeekDays_DATA =cur_time.weekday;( x, e. g7 u( t9 A# ]6 o& o
  MicoRtcSetTime(&cur_time);            //初始化 RTC 时钟的时间
9 E1 ]+ h) Q8 c5 ~# ~- L}$ x/ k5 a: y7 \- Y1 y  m
/*************************************************. {# D" T, x( }6 C7 K& e1 K
* Function:  RTC时间允许读取函数
3 C+ K+ j/ f3 }2 h: g * parameter
( B& U8 p; f5 g1 E! p+ a0 b2 F * Return
$ e1 w- {: z- u, S * Modify:
/ _$ ~  g6 I1 J) m* a4 j/ u/ ^* r**************************************************/4 R3 c( j2 {  |* c: \2 {$ E
void RTC_Time_Run(unsigned int arg)( U/ @- v4 V. _2 \' k6 Z* d# f' Z
{
# W8 d3 W0 d. |, I5 u  RTC_Time_Init();
8 V# c1 x8 [' W; O6 ^# ?" |. Z' L while(1)
: S0 _, i" p  q  p4 A {
! Q& c( v: J, L  MicoRtcGetTime(&cur_time); //返回新的时间值$ i0 T2 h2 ]2 I- K. F
  sleep(1000);
4 d: _5 d- n5 g% T }
8 N& p' u/ r9 g/ Y; Z}( S6 X6 R1 p2 R  e1 c
! z2 [) N' \* q1 o  z9 z

/ `2 n) V% x( c3 o# Q/ estatic void micoNotify_ConnectFailedHandler(OSStatus err, void* inContext)4 A1 ^% F2 ]  a/ n7 s+ J5 t
{
! f4 y! j1 m( |" I# v$ z  wifi_station_log("join Wlan failed Err: %d", err);
0 n' Q2 [( ?0 q) L6 F- _( n}2 T7 r! P' T1 ]2 q7 ^, a* X

5 `( X! ?6 f, I" |static void mqtt_proc(mico_thread_arg_t arg)
/ G4 x4 Y6 R; ?& {8 e, [{% a8 n) z' }2 g, m0 P5 p- R% G9 l
  wifi_station_log("start running mqtt_proc thread");
! n& a" Y8 ?1 S   //easylink_extra_data;
: ~' _# e! t$ W# {; a  mqtt_client_demo();3 I8 \+ @' H0 F$ s1 N% e: ]7 {
  wifi_station_log("end running mqtt_proc thread");
3 S1 s3 d" R+ o  mico_rtos_delete_thread(NULL);+ Y6 {+ t2 C2 O, `5 |
}8 A! z8 z' j9 E9 x2 x  h% P1 i
# G- y5 p) n6 e6 M& @# _
static void micoNotify_WifiStatusHandler(WiFiEvent event,  void* inContext)0 K% {& c6 q0 l. O; I
{
5 x1 i1 o3 [+ Z0 `  h  APPD = 1;
& r0 M& P2 W3 `6 w, X. Q  switch (event)
* _. D  k% W1 y1 k" U: c  {( ^# j: p' P* n3 W2 Q
  case NOTIFY_STATION_UP:" K+ {; L# e7 A( r0 ]0 A$ _3 C5 U
    wifi_station_log("Station up");/ J( i( k- Z: n6 [0 P8 G
+ p" I7 ~% E5 v. {6 F7 R  I

: }/ K) i$ v, u# V- }8 X7 N5 I5 u  //  wifi_station_log(da);
; q3 N. s( n. [4 l! n    //aliyun_iot_mqtt_network_event_callback(ALI_IOT_NETWORK_CONNECTED, NULL);
! ~8 o6 R, e  b9 i    if(1 == isMqttThreadEnter)
9 q% j& f/ b9 L  f' z+ r    {7 f0 g" E3 E- O) @, @# p! m" a( ~
      wifi_station_log("mqtt thread already running");
) t4 F  y' h4 z# F5 ~2 A      return;
* z, F* x( v+ E  ]# u7 P) [2 M    }6 H0 b3 y* F- M
    mico_thread_t threadHandle;  N9 N/ u4 K* @) i* G# M7 W: a
    mico_rtos_create_thread(&threadHandle, 1, "mqtt_thread", mqtt_proc, 1024*16, NULL);) G1 k* t: C4 P! S/ K$ s. F3 C0 S
    isMqttThreadEnter++;
3 {* N2 @  A; v% c' h    break;
$ T/ D, R* U0 J* O4 d# t* p) _. w2 x* d% X4 d, q
    break;
8 b# P- t0 b5 f. }. }7 j& [' R  case NOTIFY_STATION_DOWN:
6 a, \. j' ]% j" M    wifi_station_log("Station down");) f) U' z8 q9 ], c
    break;; J! [# c. l* k+ L
  default:5 Z. @0 `( E3 \' [5 \# ~
    break;
# d+ `$ s2 A) n* j# Z  }; P, [1 L& S& }% Z8 O+ e' a
}
" k/ ]4 ?+ r8 h* O0 s; k5 u9 }2 |* `' W( n$ `( `
int application_start( void )% t" v, f  {$ K$ U
{ ) u. ?& p1 M* q
  OSStatus err = kNoErr;5 H/ d2 [4 g% s% L
  char str[10] = {0};
# y/ q" k* M* r" B* h8 K- ]  unsigned char sssf[2]={0};
& b. F6 `# w2 Q' a8 e; ^- J. `4 x//   mico_thread_t t_handler = NULL;/*线程句柄*/ ) u  T- n# n6 `/ W
  MicoInit();
, ~8 A- t6 z9 K) E+ x: d6 X6 R9 v- W; V- _. w9 F8 [% ^' F; F
  AT24CXX_sensor_init();//初始化I2C/ E0 c8 g+ B/ B3 f! s  ~
  /* Start MiCO system functions according to mico_config.h,
( O  I1 B9 P6 D9 \7 @! r: k  i     Define macro MICO_WLAN_CONNECTION_ENABLE to enable wlan connection function6 W  ]/ V1 a- f* s. W1 q; D
     Select wlan configuration mode: MICO_CONFIG_MODE
. p' k* _+ O; H* J, U- m& |. w     Define EasyLink settings */
) N* F: A$ r# a; P( l( S  err = mico_system_init( mico_system_context_init( 0 ) );                      //' b5 D. |% Y5 Q* o4 V

$ @, {  a$ [1 c, H5 Y. B  /* Register user function when wlan connection status is changed */
' O. ~+ N9 k% I& Z9 G  err = mico_system_notify_register( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler, NULL );2 l3 c" q0 T# h  P% h

! i- b) q! ~; X. M% |  /* Register user function when wlan connection is faile in one attempt */) A' w) X6 ^7 R2 m7 R! F9 n4 `1 c
  err = mico_system_notify_register( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler, NULL );8 |/ ]) h: U5 L, P6 a

0 H+ d& d% D' p1 l# b
- b5 ]* ]% [. H9 p8 A      err = mico_rtos_create_thread(NULL,MICO_APPLICATION_PRIORITY,"RTC Time Run",RTC_Time_Run,500,NULL);//创建并启动一个新的线程
' j+ l2 w4 w( x+ x* }
" N: Y5 @( S# I8 P7 G: C% r: P9 A/ V  ext_rgb_led_log("rgb led conrtol demo(RGB_MODE)");
8 E: t) S# h3 m* U4 ^3 V
8 L, u5 f) b3 r! H& j. N  /*LED1初始化*/
6 a4 T" {3 u2 l+ V8 ^) F  err = RUN_LED_init();# x5 c9 y, I4 M$ w/ \0 o  A
6 E' ~) B5 ^9 B6 m
  /* 初始化 直流电机 */
) d/ M. b" M- K* c' T//  err = dc_motor_init(); 6 Z) R: N' }: s, C" J3 V8 @

$ ~0 E5 X2 D2 h, n5 C9 C; @( f' m6 q- f$ c
  /*初始化 温度 湿度*/
% B; i+ d# v+ _9 Q2 ^//  err = DHT11_Init();
" o/ T% _  k( U  q- E0 t. P  AT24CXX_Write_RegData(0x00,0X55);9 b  K) D8 e- b9 k" ~
//  AT24CXX_Read_RegData(0x00,sssf);
0 n' J) ^: z# A/ w# W, s) t  T  Q  APPD =0x55;//sssf[0]; 0 U- s) Y; O# c7 ]$ c5 G* ^2 D8 `
  ext_rgb_led_log("%d",APPD);
  o2 l' m) \. E" d' O& ?( L//  sprintf(str,"%d",APPD);4 m# e/ w3 Q' q3 `
  /*初始化 光发射二极管*/ $ F6 _# |, n9 H
  OLED_Init();
& N' ]! d' N- E3 Y  OLED_ShowString(0, 2,str);, h3 u; v& |2 K
0 \" v" j0 O3 D5 s9 L1 P% O4 R
  /*初始化光强传感器*/ 4 S9 k1 U1 I  d: I
//  err = light_sensor_init();
2 X' D$ ]% }- |2 W1 G! A6 `% e1 `! |. J8 k/ o% D, K
  /*按键初始化*/
% }8 E( I0 R, @2 ]  ~, h2 `//  GPIO_KEY_Init();  `  y' K( V8 Y. [9 h
8 ~2 J% \9 |. ~1 a

% R' X( [0 P) S, v2 ~  mico_rtos_delete_thread(NULL);
7 Y' n/ Z6 ]9 X( h5 i/ {5 D9 v  return err;  G. c, X- J9 S! \1 d
}
5 c% L2 m  {* T4 G
) ]( l0 a; m( t
0 v  ~5 l9 [* Q
4 J' Y6 S3 \4 `, {
9 x' H+ U6 k. p4 X

更多回帖

发帖
×
20
完善资料,
赚取积分