CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
CMPS03 Digital Compass Module âÁ´Ù Å à¢ç Á ·Ô È ´Ô ¨Ô µ ÍÅ
l
1
Distributed by Innovative Experiment Co.,Ltd., Thailand
¤Ø³ÊÁºÑµÔ 㪠ä¿àÅÕÂé § +5V µ ͧ¡ÒáÃÐáÊä¿¿ Ò 20mA l 㪠µÇ Ñ µÃǨ¨ÑºÊ¹ÒÁáÁ àËÅç¡àºÍà KMZ51 ¢Í§ Philips ¨íҹǹ 2 µÑÇ à¾×Íè ãË ÊÒÁÒöµÃǨ¨ÑºÊ¹ÒÁ áÁ àËÅç¡âÅ¡ä´ Í ҧÊÁºÙó áÅÐÁÕ¤ÇÒÁÅÐàÍÕ´ÁÒ¡à¾Õ§¾Í l ¤ÇÒÁÅÐàÍÕ´¢Í§ÁØÁ 0.1 ͧÈÒ l ¤ Ò¤ÇÒÁ¼Ô´¾ÅÒ´ 3-4 ͧÈÒ â´Â»ÃÐÁÒ³ ËÅѧ¨Ò¡¡ÒûÃѺᵠ§ l àÍÒµ ¾µ Ø áººÊÑÒ³¾ÑÅÊ ¤ÇÒÁ¡Ç Ò§ 1 ¶Ö§ 37 ÁÔÅÅÔÇ¹Ô Ò·Õ â´ÂÁÕ굄 ÃÒà¾ÔÁè ¤Ãѧé ÅÐ 0.1 ÁÔÅÅÔÇ¹Ô Ò·Õ l àÍÒµ ¾µ Ø ¢ ÍÁÙÅ´Ô¨µÔ Íż Ò¹¡ÒõԴµ ÍÃкººÑÊ I2C ÃͧÃѺÊÑÒ³¹ÒÌ ¡Ò¤ÇÒÁ¶ÕÊè §Ù ¶Ö§ 1MHz â´ÂãË ¢Í ÁÙÅ 2 ÃٻẺ¤×Í 0-255 áÅÐ 0-3599 l ¢¹Ò´àÅç¡à¾Õ§ 32 x 35 ÁÔÅÅÔàÁµÃ l Ê×Í è ÊÒáѺäÁâ¤Ã¤Í¹â·ÃÅàÅÍà ÂÍ´¹ÔÂÁä´ ·¡Ø µÃСÙÅ ÍÒ·Ô àºÊÔ¡áʵÁ» 2SX/2P, PIC, MCS-51, PSoC, 68HC11 ·Ñ§é ¼ Ò¹ÃкººÑÊ I2C áÅд Ç¡ÒÃÇÑ´ÊÑÒ³¾ÑÅÊ l
ÍØ»¡Ã³ àÊÃÔÁ ºÍà ´ ADX-CMPS03 «Ö§è à» ¹ºÍà ´ÍÐá´»àµÍà ÊÒí ËÃѺÍíÒ¹ÇÂÊдǡ㹠¡ÒÃàª×Íè Áµ ͡ѺºÍà ´äÁâ¤Ã¤Í¹â·ÃÅàÅÍà áÅÐἧµ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ l
l
ÊÒ PCB3A ÊíÒËÃѺàª×Íè Áµ ͡ѺºÍà ´¤Çº¤ØÁËع ¹µ ¢Í§ i-nex
2
l
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨ÔµÍÅ CMPS03 à» ¹¼Å§Ò¹¢Í§ Devantech (www.radio-electronics.co.uk) Í͡ẺÁÒà¾×Íè ª ÇÂ㹡ÒáíÒ˹´·ÔÈ·Ò§¡ÒÃà¤Å×Íè ¹·Õ¢è ͧËع ¹µ 굄 â¹ÁÑµÔ áÅйíÒÁÒ㪠㹡ÒÃÊà ҧ à¤Ã×Íè §Á×ÍÇÑ´áÅеÃǨÊͺ·ÔÈÃкºÍÔàÅç¡·ÃÍ¹Ô¡Ê â´ÂËÑÇã¨ÊíҤѢͧâÁ´ÙÅ CMPS03 ¤×Í µÑǵÃǨ ¨ÑºÊ¹ÒÁáÁ àËÅç¡àºÍà KMZ51 ¢Í§ Philips ¨íҹǹ 2 µÑÇ à¾×Íè ãË Á¤Õ ÇÒÁäÇà¾Õ§¾Í㹡ÒõÃǨ¨Ñº ʹÒÁáÁ àËÅç¡âÅ¡ (Earth magnetic field) áÅÐäÁâ¤Ã¤Í¹â·ÃÅàÅÍà à¾×Íè ÃѺÊÑÒ³¨Ò¡µÑǵÃǨ¨Ñº ÁÒ»ÃÐÁÇżÅà» ¹¢ ÍÁÙÅ´Ô¨ÔµÍÅáÅÐÊÑÒ³¾ÑÅÊ ÊíÒËÃѺᨠ§¼Å¡ÒÃÇÑ´·ÔÈ·Ò§
1. µíÒá˹ §¢ÒáÅСÒõ Í㪠§Ò¹ ã¹ÃÙ»·Õè 1 áÊ´§Ãٻà ҧ˹ ÒµÒáÅСÒèѴ¢Ò¢Í§ CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ ¨ÐàËç¹Ç Òà» ¹ ἧǧ¨Ã·ÕÁè ¤Õ Í¹à¹ç¡àµÍà µÍ ÍÍ¡ÁÒà¾×Íè ãË àª×Íè Áµ Íä»ãª §Ò¹ Í ҧäáçµÒÁà¾×Íè ÍíҹǤÇÒÁÊдǡ á¡ ¼ãÙ ª §Ò¹¡ÑººÍà ´¤Çº¤ØÁËع ¹µ ¢Í§ºÃÔÉ·Ñ ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔàÁ¹µ ¨íÒ¡Ñ´ (i-nex : à» ¹µÑÇá·¹ ¨íÒ˹ ÒÂÊÔ¹¤ Ңͧ Devantech ã¹»ÃÐà·Èä·ÂÍ ҧ໠¹·Ò§¡ÒÃ) ¨Ö§ä´ ¾Ñ²¹ÒºÍà ´ÍÐá´»àµÍà ÃØ ¹ ADX-CMPS03 à¾×Íè ãË ¹Òí âÁ´ÙÅ CMPS03 ÁÒµÔ´µÑ§é (â´ÂºÍà ´ ADX-CMPS03 µ ͧ¨Ñ´«×Íé á¡) º¹ºÍà ´ ADX-CMPS03 ä´ ¨´Ñ àµÃÕÂÁ¤Í¹à¹ç¡àµÍà PCB 3 ¢ÒµÑǼÙÊ Òí ËÃѺàª×Íè Áµ ͡ѺºÍà ´ ¤Çº¤ØÁËع ¹µ áÅФ͹à¹ç¡àµÍà IDC µÑÇàÁÕÂá¶Çà´ÕÂè Ç 4 ¢ÒÊíÒËÃѺàÊÕºÊÒµ Íǧ¨ÃàºÍà AWG#22 à¾×Íè µ ͡Ѻἧµ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ ¹Í¡¨Ò¡¹Ñ¹é ÂѧÁÕÊÇÔµª ¡´ÊíÒËÃѺ»ÃѺµÑ§é ¤ Ò (calibration) à¾×Íè ¡íÒ˹´µíÒá˹ §·ÔÈÍ Ò§ÍÔ§ â´Âǧ¨Ã¢Í§ºÍà ´ ADX-CMPS03 áÊ´§ã¹ÃÙ»·Õè 2 µÑǵÃǨ¨ÑºÊ¹ÒÁáÁ àËÅç¡ KMZ51 äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ËÅÑ¡ÊíÒËÃѺ»ÃÐÁÇżŠ¡ÃÒÇ´ äÁ µ Í㪠§Ò¹ ¤ÇÒÁ¶Õè 50/60Hz »ÃѺµÑ§é ¤ Ò¡ÒÃÇÑ´ äÁ µ Í㪠§Ò¹ àÍÒµ ¾µØ ẺÊÑÒ³¾ÑÅÊ SDA ÊíÒËÃѺàª×Íè Áµ ͼ Ò¹ÃкººÑÊ I2C SCL ÊíÒËÃѺàª×Íè Áµ ͼ Ò¹ÃкººÑÊ I2C +5V ´ ҹ˹ ҢͧâÁ´ÙÅ CMPS03
ÃÙ»·Õè 1 áÊ´§Ãٻà ҧáÅеíÒá˹ §¢ÒÊíÒËÃѺ¡Òõ Í㪠§Ò¹
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
3
33.0mm
ADX-CMPS03
K1 SCL
l
R1 4.7k
S1 CAL
K4 I2C BUS
front +5V SCL SDA CMPS-03 PWM Digital Compass NC CAL 50/60Hz NC GND
+5V
GND SCL SDA +5V
K3 PWM
28.6mm
31.5mm 26.7mm
>31.5mm
K2 SDA
R2 4.7k
PWM
>33.0mm
¤Í¹à¹ç¡àµÍà µÑÇàÁÕ ÊíÒËÃѺµÔ´µÑ§é âÁ´ÙÅ CMPS03
¤Í¹à¹ç¡àµÍà PCB ¢Í§ ÊÑÒ³ÃкººÑÊ I2C
GND
¨Ø´µ ÍÊÑÒ³¢Í§ÃкººÑÊ I2C ÊíÒËÃѺàÊÕºÊÒµ Íǧ¨Ãà¾×èÍ㪠¡ÑººÍà ´·´ÅͧËÃ×Í á¼§µ Íǧ¨Ã (àºÃ´ºÍà ´) ÊÇÔµª ¡´µÔ´»Å Í´ѺÊíÒËÃѺ»ÃѺᵠ§à¾×Íè ËÒµíÒá˹ § Í Ò§ÍÔ§ (calibration) ¤Í¹à¹ç¡àµÍà PCB ¢Í§àÍÒµ ¾µØ ÊÑÒ³¾ÑÅÊ
ÃÙ»·Õè 2 áÊ´§Ç§¨Ã¢Í§ºÍà ´ ADX-CMPS03 áÅСÒÃàª×Íè Áµ ͡ѺâÁ´ÙÅ CMPS03
2. ¡ÒûÃѺᵠ§¤ Ò·ÔÈ·Ò§Í Ò§ÍԧᡠâÁ´ÙÅ CMPS03
à¾×Íè ãË ¡ÒÃÇÑ´·ÔÈ·Ò§¢Í§âÁ´ÙÅ CMPS03 ÁÕ¤ÇÒÁáÁ ¹ÂíÒÁÒ¡·ÕÊè ´Ø ¨Ö§ÁÕÍ¹Ô ¾ØµÊíÒËÃѺ»ÃѺᵠ§ ¤ Ò·Ô·Ò§Í Ò§ÍÔ§ ·Ñ駹Õé¾×èÍ»ÃÐ⪹ 㹡ÒáíÒ˹´·ÔÈ·Ò§Í Ò§Íԧ੾ÒÐÊíÒËÃѺ¼Ù 㪠§Ò¹ â´Âµ ͧ» ͹ ÊÑÒ³Åͨԡ 0 ࢠҷբè ÒÍÔ¹¾ØµÊíÒËÃѺ»ÃѺᵠ§âÁ´ÙÅ CMPS03 «Ö§è ¡ç¤Í× ¢Ò 6 Ëҡ㪠ºÍà ´ ADXCMPS03 ¡ÑºâÁ´ÙÅ CMPS03 ¨ÐÁÕÊÇÔµª ¡´µÔ´»Å Í´ѺµÔ´µÑ§é äÇ ãË áÅ Ç ¡ÒûÃѺᵠ§ÁÕ¢¹Ñé µÍ¹´Ñ§¹Õé (1) ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×¹é Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔÈà˹×Í ¡´ÊÇÔµª 1 ¤Ãѧé (2) ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×¹é Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔȵÐÇѹÍÍ¡ ¡´ÊÇÔµª (3) ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×¹é Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔÈãµ ¡´ÊÇÔµª 1 ¤Ãѧé (4) ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×¹é Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔȵÐÇѹµ¡ ¡´ÊÇÔµª à» ¹ÍѹÊÔ¹é ÊØ´¡ÒûÃѺµÑ§é ¤ Ò·ÔÈ·Ò§Í Ò§ÍÔ§¢Í§âÁ´ÙÅ CMPS03 â´ÂâÁ´ÙŨÐà¡çº¤ ÒÍ Ò§ÍÔ§¹Õäé Ç ã¹Ë¹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁáÅÐäÁ µ ͧ»ÃѺµÑ駤 ÒãËÁ ÍÕ¡àÁ×èͨ ÒÂä¿àÅÕ駤ÃÑé§ãËÁ
4
l
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
3. ¡ÒÃÍ Ò¹¤ ÒÊÑÒ³àÍÒµ ¾µØ ¢Í§âÁ´ÙÅ CMPS03 3.1 ¡ÒÃÍ Ò¹¤ Ò·ÔÈ·Ò§¨Ò¡àÍÒµ ¾µØ ÊÑÒ³¾ÑÅÊ ¡ÒÃÍ Ò¹¤ ÒÊÑÒ³ã¹âËÁ´¹Õé à» ¹¡ÒùíÒ¤ Ò¤ÇÒÁ¡Ç Ò§¾ÑÅÊ ·Õèä´ ¨Ò¡àÍÒµ ¾ØµÊÑÒ³¾ÑÅÊ ¢Í§âÁ´ÙÅ CMPS03 ÁÒÃкصÒí á˹ §Í§ÈÒ ¨Ò¡ 0 ¶Ö§ 359.9 ͧÈÒ â´ÂÁÕÂÒ ¹¢Í§¤ Ò¤ÇÒÁ¡Ç Ò§ÊÑÒ³ ¾ÑÅÊ ¨Ò¡ 1 ÁÔÅÅÔÇ¹Ô Ò·Õ仨¹¶Ö§ 36.99 ÁÔÅÅÔÇ¹Ô Ò·Õ ÁÕ¤ÇÒÁÅÐàÍÕ´ 0.1 ÁÔÅÅÔÇ¹Ô Ò·ÕµÍ Í§ÈÒ ã¹ÊÑÒ³ ¾ÑÅÊ áµ ÅÐä«à¡ÔÅ ÁÕªÇ §Åͨԡ 0 ¡Ç Ò§ 65 ÁÔÅÅÔÇ¹Ô Ò·Õ ´Ñ§¹Ñé¹ã¹¡ÒùíÒÊÑÒ³¾ÑÅÊ ÁÒ»ÃÐÁÇżÅà» ¹¤ ÒÁØÁ ¨Ö§µ ͧ㪠¡ÒùѺ¤ÇÒÁ¡Ç Ò§¢Í§ ÊÑÒ³¾ÑÅÊ à» ¹ËÅѡ㹡ÒäíҹdzËÒ¤ ÒÁØÁ·Õâè Á´ÙÅ CMPS03 ÇÑ´ä´
3.1.1 µÑÇÍ ҧâ»Ãá¡ÃÁ·Õãè ª ¤Çº¤ØÁÊíÒËÃѺàºÊÔ¡áʵÁ» 2SX áÅÐ i-Stamp ¡ÒÃ㪠§Ò¹Ã ÇÁ¡ÑºàºÊÔ¡áʵÁ» 2SX áÅÐ i-Stamp ¹Ñ¹é ¨Ð㪠¤Òí Êѧè PULSIN 㹡ÒùѺÊÑÒ³ ¾ÑÅÊ â´Â¨Ðà¾ÔÁè ¤ Ò¡ÒùѺ¢Ö¹é ·Ø¡æ 0.8 äÁâ¤ÃÇÔ¹Ò·Õ ´Ñ§¹Ñ¹é ·Õ¤è ÇÒÁ¡Ç Ò§¢Í§¾ÑÅÊ ·Õè 1 ÁÔÅÅÔÇ¹Ô Ò·ÕÊÒí ËÃѺ µíÒá˹ § 0 ͧÈÒ àºÊÔ¡áʵÁ» 2SX áÅÐ i-Stamp ¨Ð¹Ñº¤ Òä´ à· Ò¡Ñº 1,250 ¨Ö§ÊÒÁÒö㪠¤Ò ¹Õàé » ¹¨Ø´ Í Ò§ÍÔ§·Õè 0 ͧÈÒ àÁ×Íè µ ͧ¡Ò÷ÃÒº¤ ÒÁØÁ·Õáè Á ¨ÃÔ§ ãË ¹Òí ¤ ÒÁØÁ·Õ¹è ºÑ ä´ Åº´ Ç 1,250 áÅ ÇËÒô Ç 125 ¡ç¨Ðä´ ¤Ò ÁØÁã¹Ë¹ ÇÂͧÈÒ·Õµè Í §¡Òà ÃÒÂÅÐàÍÕ´¢Í§â»Ãá¡ÃÁáÊ´§ã¹â»Ãá¡ÃÁ·Õè 1 ·Õ¤è ÇÒÁ¡Ç Ò§¾ÑÅÊ Ê§Ù ÊØ´¤×Í 36.99 ÁÔÅÅÔÇ¹Ô Ò·Õ ¤ Ò·Õ¹è ºÑ ä´ ¨Ò¡¤íÒÊѧè PULSIN ෠ҡѺ 46,237 àÁ×Íè ź´ Ç 1,250 áÅ ÇËÒô Ç 125 à¾×Íè á»Å§à» ¹Í§ÈÒ ¤ ÒÊÙ§ÊØ´·Õáè Ê´§à» ¹¼ÅÅѾ¸ ä´ ¤Í× 359 à» ¹¤ Ò Ë¹ ÇÂͧÈÒÊÙ§ÊØ´¹Ñè¹àͧ ËÁÒÂàËµØ ã¹ºÒ§¡Ã³Õ ¤ Ò·ÕÍè Ò ¹ä´ ʧ٠ÊØ´¨Ò¡¤íÒÊѧè PULSIN ÍÒ¨äÁ ¶§Ö 46,237 ¼Ùã ª §Ò¹ÊÒÁÒö »ÃѺà»ÅÕÂè ¹¡ÒäíҹdzãËÁ ãË ä´ ÁÁØ à» ¹ 359.9 ͧÈÒä´ '{$STAMP BS2sx} '{$PBASIC 2.5} bearing VAR WORD main: PULSIN 4, 1, bearing bearing = (bearing-1250)/125 DEBUG "Compass Bearing
' Get reading ' BS2sx - Calculate Bearing ' in degrees ", DEC3 bearing ,CR ' Display Compass Bearing
GOTO main
â»Ãá¡ÃÁ·Õè 1 áÊ´§¡ÒÃÍ Ò¹¤ ÒÊÑÒ³¾ÑÅÊ ¨Ò¡âÁ´ÙÅ CMPS03
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
l
5
µíÒá˹ §ÃÕ¨ÔÊàµÍà ÃÒÂÅÐàÍÕ´ 0 µÑÇàÅ¢áÊ´§ÃØ ¹¢Í§ºÍà ´ CMP03 1 Ê §¤ ÒµíÒá˹ §áººËÂÒº (0-255) Ê §¤ ÒµíÒá˹ §áººÅÐàÍÕ´´ ǵÑÇàÅ¢ 16 ºÔµ (0-3599) 2,3 ÊÒÁÒöá»Å§¤ Òà¾×èÍáÊ´§Í§ÈÒ 0-359.9 ͧÈÒä´ â´ÂµÃ§ ÊíÒËÃѺµÃǨÊͺ¤ ÒÀÒÂã¹ â´Â¨ÐáÊ´§¤ Ò¤ÇÒÁµ Ò§¢Í§ 4,5 Sensor1 à» ¹µÑÇàÅ¢ 16 ºÔµáºº¤Ô´à¤Ã×èͧËÁÒ ÊíÒËÃѺµÃǨÊͺ¤ ÒÀÒÂã¹ â´Â¨ÐáÊ´§¤ Ò¤ÇÒÁµ Ò§¢Í§ 6,7 Sensor2 à» ¹µÑÇàÅ¢ 16 ºÔµáºº¤Ô´à¤Ã×èͧËÁÒ áÊ´§¤ ÒµÑÇàÅ¢¡ÒûÃѺᵠ§ÀÒÂã¹ (calibration value1) 8,9 à» ¹µÑÇàÅ¢ 16 ºÔµáºº¤Ô´à¤Ã×èͧËÁÒ áÊ´§¤ ÒµÑÇàÅ¢¡ÒûÃѺᵠ§ÀÒÂã¹ (calibration value2) 10,11 à» ¹µÑÇàÅ¢ 16 ºÔµáºº¤Ô´à¤Ã×èͧËÁÒ 12,13 äÁ 㪠§Ò¹Í Ò¹¤ Òä´ à» ¹ 0 14 äÁ 㪠§Ò¹ äÁ ä´ ¡íÒ˹´¤ ÒäÇ ¤íÒÊÑè§ÊíÒËÃѺ¡ÒûÃѺᵠ§¤ Ò â´ÂàÁ×è͵ ͧ¡ÒûÃѺᵠ§¤ Ò 15 µ ͧà¢Õ¹¢ ÍÁÙÅ 255 ࢠҷÕèÃÕ¨ÔÊàµÍà µíÒá˹ §¹Õé
µÒÃÒ§·Õè 1 áÊ´§µíÒá˹ §ÃÕ¨ÊÔ àµÍà ÀÒÂã¹âÁ´ÙÅ CMPS03
3.2 ¡ÒÃÍ Ò¹¤ Ò·Ôȷҧ໠¹¢ ÍÁÙÅ´Ô¨µÔ Íż Ò¹ÃкººÑÊ I2C ¡ÒÃÍ Ò¹¤ Ò¨Ò¡âÁ´ÙÅ CMPS03 ãË ä´ ¤Ò ·ÕÁè ¤Õ ÇÒÁáÁ ¹ÂíÒÊÙ§¤ÇÃàÅ×Í¡àÍÒµ ¾µØ ¢ ÍÁÙÅ´Ô¨µÔ Íż Ò¹ ÃкººÑÊ I2C â´ÂâÁ´ÙÅ CMPS03 ÊÒÁÒÃ¶Ê §¢ ÍÁÙŢͧµíÒá˹ §ÍÍ¡ÁÒ·Õ¤è ÇÒÁÅÐàÍÕ´ÊÙ§ÊØ´ 0.1 ͧÈÒâ´ÂäÁ ¨Òí à» ¹µ ͧÁÕ¡ÒäíҹdzËÃ×Íá»Å§¤ Òã´ æ ÍÕ¡
3.2.1 ÃٻẺ¡ÒÃÊ×Íè ÊÒâ ÍÁÙźÑÊ I2C ºÑÊ I2C àª×Íè Áµ ͡ѺäÁâ¤Ã¤Í¹â·ÃÅàÅÍà â´Â㪠ÊÒÂÊÑÒ³ 2 àÊ ¹ä´ á¡ ¢Ò SDA (ÃѺáÅÐ Ê §¢ ÍÁÙÅ) áÅÐ SCL (¢ÒÊÑÒ³¹ÒÌ ¡Ò) â´Â¢ÒÊÑÒ³·Ñ§é Êͧ¨Ðµ ͧµ ͵Ñǵ Ò¹·Ò¹¾ÙÅÍÑ»µ ÍäÇ à¾×Íè ¡íÒ˹´Ê¶Ò¹ÐÅͨԡ 1 ãË ¡ºÑ ÃкººÑÊ
3.2.2 ÅíҴѺ¢Ñ¹é ¡ÒõԴµ Í ¤ ÒáÍ´à´ÃʢͧâÁ´ÙÅ CMPS03 ¤×Í $C0 ÊíÒËÃѺ¡ÒÃÊ §¢ ÍÁÙÅ áÅÐ $C1 ÊíÒËÃѺ¡ÒÃÍ Ò¹¤ Ò ¢ ÍÁÙÅ â´Â¢Ñ¹é µÍ¹¡ÒõԴµ ͡ѺâÁ´ÙÅ CMPS03 à¾×Íè Í Ò¹¢ ÍÁÙÅÁÕ´§Ñ ¹Õé
6
l
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
S tart B it
S tart B it
áÍ´à´ÃÊÊíÒËÃÑºÊ §¤ Ò¢ ÍÁÙÅä»Âѧ CMPS03 = $CO 1
1
0
0
0
0
0
A7
A6
A5
A4
A3
A2
A1
1
2
3
4
5
6
7
0 R /W A C K
8
Start bit
¢ ÍÁÙŵíÒá˹ §ÃÕ¨ÔÊàµÍà ·Õèµ Í§¡ÒÃÍ Ò¹¤ Ò
9
áÍ´à´ÃÊÊíÒËÃÑºÍ Ò¹¤ Ò¢ ÍÁÙŨҡ CMPS03 = $C1
D7
D6
D5
D4
D3
D2
D1
D0
ACK
1
2
3
4
5
6
7
8
9
Stop bit
¢ ÍÁÙÅ 8 ºÔµ·ÕèÍ Ò¹ä´ ¨Ò¡ CMPS03
1
1
0
0
0
0
0
1
A7
A6
A5
A4
A3
A2
A1
R /W
ACK
D7
D6
D5
D4
D3
D2
D1
D0
ACK
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
ÃÙ»·Õè 3 áÊ´§ä·ÁÔ§è ä´ÍÐá¡ÃÁ¢Í§¡ÒõԴµ ÍÊ×Íè ÊÒáѺâÁ´ÙÅ CMPS03 ¼ Ò¹ÃкººÑÊ I2C 1. Ê §ºÔµàÃÔÁè µ ¹ËÃ×Í Start bit à¾×Íè ᨠ§ãË ÃкººÑÊ I2C àµÃÕÂÁ¾Ã ÍÁÃѺ¢ ÍÁÙÅ CMPS03
2. Ê §¤ ÒáÍ´à´ÃÊ $C0 à¾×èÍÃкØÇ Òµ ͧ¡ÒõԴµ Íà¾×èÍà¢Õ¹¢ ÍÁÙÅä»Âѧ¡ÑºâÁ´ÙÅ
3. Ê §¤ ÒµíÒá˹ §ÃÕ¨ÔÊàµÍà ÀÒÂã¹âÁ´ÙÅ CMPS03 ·Õèµ Í§¡ÒÃÍ Ò¹¤ Ò «Öè§ÁÕÃÒÂÅÐàÍÕ´ áÊ´§ã¹µÒÃÒ§·Õè 1 4. Ê §¤ ÒáÍ´à´ÃÊ $C1 à¾×Íè ÃкØÇÒ µ ͧ¡ÒÃÍ Ò¹¤ Ò¢ ÍÁÙŨҡâÁ´ÙÅ CMPS03 5. Í Ò¹¤ Ò¢ ÍÁÙŨҡâÁ´ÙÅ CMPS03 ÁÒà¡çºäÇ ã¹Ë¹ ǤÇÒÁ¨íÒ 6. Ê §ºÔµËÂØ´ËÃ×Í Stop à¾×Íè ËÂØ´¡ÒÃÊ×Íè ÊÒâ ÍÁÙÅ áÅСíÒ˹´ãË ºÊÑ ÍÂÙã ¹ÊÀÒÇкÑÊÇ Ò§ ¨Ò¡ÅíҴѺ¢Ñ¹é ¡ÒõԴµ ÍÊ×Íè ÊÒâ Ò§µ ¹ ÊÒÁÒö¹íÒÁÒà¢Õ¹໠¹â»Ãá¡ÃÁµÑÇÍ ҧà¾×Íè Í Ò¹¢ ÍÁÙÅ ¨Ò¡âÁ´ÙÅ CMPS03 â´Â㪠àºÊÔ¡áʵÁ» 2SX ËÃ×Í i-Stamp ä´ ´§Ñ áÊ´§ã¹â»Ãá¡ÃÁ·Õè 2
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ '{$STAMP BS2sx} '{$PBASIC 2.5} SDA SCL WrCMPS03 RdCMPS03 Ack Nak i2cSDA i2cData REGISTER i2cWork i2cAck temp digits width
CON CON CON CON CON CON VAR VAR VAR VAR VAR VAR VAR VAR
6 7 $C0 $C1 0 1 NIB WORD BYTE BYTE BIT WORD NIB NIB
' ' ' ' ' ' ' ' ' ' ' '
l
I2C serial data line I2C serial clock line write to compass read from compass acknowledge bit no ack bit I2C serial data pin data to/from device register address work byte for TX routine Ack bit from device for rj printing
Init: PAUSE 250 i2cSDA = SDA ' define SDA pin REGISTER = 0 ' compass revision number GOSUB Read_Byte DEBUG 2,1,1, "Revision Number = " ,DEC2 i2cData Main: REGISTER = 1 ' Show Data 0-255 for 0-360 degree GOSUB Read_Byte ' Read Byte From I2C DEBUG 2,1,3, "The Coarse Data(0-255) = " ,DEC i2cData REGISTER = 2 ' get Data in degrees, 0.0 - 359.9 Degree GOSUB Read_Word DEBUG 2,1,5, "Position = ",DEC i2cData/10,".",DEC1 i2cData," Degree" PAUSE 250 GOTO Main ' Compass Access Subroutines ' Writes low byte of i2cData to REGISTER Write_Byte: GOSUB I2C_Start i2cWork = WrCMPS03 GOSUB I2C_TX_Byte ' send device address i2cWork = REGISTER GOSUB I2C_TX_Byte ' send register number i2cWork = i2cData.LOWBYTE GOSUB I2C_TX_Byte ' send the data GOSUB I2C_Stop RETURN ' Writes i2cData to REGISTER Write_Word: GOSUB I2C_Start i2cWork = WrCMPS03 GOSUB I2C_TX_Byte i2cWork = REGISTER GOSUB I2C_TX_Byte i2cWork = i2cData.HIGHBYTE GOSUB I2C_TX_Byte i2cWork = i2cData.LOWBYTE GOSUB I2C_TX_Byte GOSUB I2C_Stop RETURN
' send device address ' send register number ' send the data - high byte ' send the data - low byte
â»Ãá¡ÃÁ·Õè 2 â»Ãá¡ÃÁÍ Ò¹¤ Ò¨Ò¡âÁ´ÙÅ CMPS03 ¼ Ò¹ÃкººÑÊ I2C ¢Í§ i-Stamp (ÁÕµÍ )
7
8
l
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
' Read i2cData (8 bits) from REGISTER Read_Byte: GOSUB I2C_Start i2cWork = WrCMPS03 GOSUB I2C_TX_Byte i2cWork = REGISTER GOSUB I2C_TX_Byte GOSUB I2C_Start i2cWork = RdCMPS03 GOSUB I2C_TX_Byte GOSUB I2C_RX_Byte_Nak GOSUB I2C_Stop i2cData = i2cWork RETURN ' Read i2cData (16 bits) from REGISTER Read_Word: GOSUB I2C_Start i2cWork = WrCMPS03 GOSUB I2C_TX_Byte i2cWork = REGISTER GOSUB I2C_TX_Byte GOSUB I2C_Start i2cWork = RdCMPS03 GOSUB I2C_TX_Byte GOSUB I2C_RX_Byte i2cData.HIGHBYTE = i2cWork GOSUB I2C_RX_Byte_Nak GOSUB I2C_Stop i2cData.LOWBYTE = i2cWork RETURN ' Low Level I2C Subroutines 'Start I2C_Start: INPUT i2cSDA INPUT SCL LOW i2cSDA Clock_Hold: IF (INS.LOWBIT(SCL) = 0) THEN Clock_Hold RETURN 'Transmit I2C_TX_Byte: SHIFTOUT i2cSDA,SCL,MSBFIRST,[i2cWork\8] SHIFTIN i2cSDA,SCL,MSBPRE,[i2cAck\1] RETURN 'Receive I2C_RX_Byte_Nak: i2cAck = Nak GOTO I2C_RX I2C_RX_Byte: i2cAck = Ack I2C_RX: SHIFTIN i2cSDA,SCL,MSBPRE,[i2cWork\8] SHIFTOUT i2cSDA,SCL,LSBFIRST,[i2cAck\1] RETURN 'Stop I2C_Stop:
LOW i2cSDA INPUT SCL INPUT i2cSDA RETURN
' send compass address ' send register number ' repeat start (sets register) ' send read command ' return the data
' send compass address ' send register number ' repeat start (sets register) ' send read command ' read high byte of data ' read low byte of data
' I2C start bit sequence ' SDA -> low while SCL high ' device ready?
' send byte to device ' get acknowledge bit
' no Ack = high ' Ack = low ' get byte from device ' send ack or nak
' I2C stop bit sequence ' SDA --> high while SCL high
â»Ãá¡ÃÁ·Õè 2 â»Ãá¡ÃÁÍ Ò¹¤ Ò¨Ò¡âÁ´ÙÅ CMPS03 ¼ Ò¹ÃкººÑÊ I2C ¢Í§ i-Stamp (ÁÕµÍ )
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
l
9
ÃÙ»·Õè 4 áÊ´§Ë¹ Ҩͧ͢ Debug terminal áÊ´§¢ ÍÁÙÅ·ÕÍè Ò ¹ä´ ¨Ò¡âÁ´ÙÅ CMPS03
3.2.3 ¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ·Õè 2 µÔ´µ ͡ѺâÁ´ÙÅ CMPS03 ¼ Ò¹ÃкººÑÊ I2C ´ Ç i-Stamp à¹×Íè §¨Ò¡àºÊÔ¡áʵÁ» 2SX áÅÐ i-Stamp äÁ Á¤Õ Òí ÊÑ§è µÔ´µ ͡ѺÃкººÑÊ I2C ´Ñ§¹Ñ¹é â»Ãá¡ÃÁ µÔ´µ ͡ѺâÁ´ÙÅ CMPS03 ¼ Ò¹ÃкººÑÊ I2C ¨Ö§¤ ͹¢ Ò§ÂÒÇ à¹×Íè §¨Ò¡µ ͧÊà ҧâ»Ãá¡ÃÁ ÍÂÊíÒËÃѺ ¡ÒÃÊ×Íè ÊÒâ ÍÁÙšѺÃкººÑÊ I2C ËÅѧ¨Ò¡¹Õ¼é ãÙ ª §Ò¹ÊÒÁÒö¹íÒâ»Ãá¡ÃÁ Í¹Õäé »»ÃÐÂØ¡µ 㪠§Ò¹ ¡ÑºÍØ»¡Ã³ µÑÇÍ×è¹æ ·Õèä´ ãª ¡ÒõԴµ ÍÃкººÑÊ I2C ä´ ·Ñ¹·Õ ÊíÒËÃѺ¢Ñ鹵͹¡Ò÷íÒ§Ò¹ËÅÑ¡æ ¢Í§â»Ãá¡ÃÁ·Õè 2 ÁÕ´§Ñ ¹Õé 1. ¡íÒ˹´ÃÕ¨ÊÔ àµÍà ໠¹ 0 à¾×Íè µÔ´µ ÍÍ Ò¹¤ ÒàÇÍà ª¹Ñ ¢Í§âÁ´ÙÅ CMPS03 ¨Ò¡¹Ñ¹é Í Ò¹ ¤ ÒÁÒáÊ´§·ÕËè ¹ Òµ Ò§ Debug terminal 2. ãË â»Ãá¡ÃÁǹÅÙ»·Õâè »Ãá¡ÃÁËÅÑ¡ ¨Ò¡¹Ñ¹é Ê §¤ ÒÃÕ¨ÊÔ àµÍà ෠ҡѺ 1 à¾×Íè Í Ò¹¤ Ò ¢ ÍÁÙÅẺËÂÒºÍÍ¡ÁÒ áŠǹíÒÁÒáÊ´§¼Å·ÕËè ¹ Òµ Ò§ Debug terminal 3. Ê §¤ ÒÃÕ¨ÊÔ àµÍà ෠ҡѺ 2 à¾×Íè Í Ò¹¤ Ò¢ ÍÁÙÅẺÅÐàÍÕ´ ¨Ò¡¹Ñ¹é Êѧè Í Ò¹¤ Ò¢ ÍÁÙŨҡ ºÑÊ I2C ẺàÇÔô (Í Ò¹¢ ÍÁÙÅÍÍ¡ÁÒ 16 ºÔµ ) 4. ¹íÒ¤ Ò¢ ÍÁÙÅ·Õäè ´ ËÒô Ç 10 ¡ ͹à¾×Íè á»Å§¤ Ò·Õäè ´ à» ¹Í§ÈÒ áÊ´§·ÕËè ¹ Òµ Ò§ Debug terminal ¨Ò¡¹Ñ¹é ¹íÒ¤ ÒËÅÑ¡ÊØ´· ÒÂÁÒáÊ´§ «Ö§è µíÒá˹ §ÊØ´· ÒÂà» ¹µíÒá˹ §¢Í§¨Ø´·È¹ÔÂÁ
10
l
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
3.3.4 ¡ÒûÃѺᵠ§¤ ҢͧâÁ´ÙÅ CMPS03 ¼ Ò¹·Ò§ÃкººÑÊ I2C ¡ÒûÃѺᵠ§¤ Ò·íÒä´ â´Â¡ÒÃÊ §¤ Ò 0xFF ä»ÂѧÃÕ¨ÊÔ àµÍà 15 ¢Í§âÁ´ÙÅ CMPS03 â´Â¨Ðµ ͧ Ê §¤ Ò 4 ¤Ãѧé áÅÐÃкطÈÔ ·Ò§ËÅÑ¡æ 4 ·Ôȷҧઠ¹à´ÕÂǡѺ¡ÒáíÒ˹´¤ Ò´ ÇÂÊÇÔµª â´ÂµÃ§ ÁÕ¢¹Ñé µÍ¹ ´Ñ§¹Õé 1. ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×¹é Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔÈà˹×Í ¨Ò¡¹Ñ¹é à¢Õ¹¤ Ò 255 (0xFF) ä»ÂѧÃÕ¨ÊÔ àµÍà 15 2. ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×¹é Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔȵÐÇѹÍÍ¡ à¢Õ¹ ¤ Ò 255 (0xFF) ä»ÂѧÃÕ¨ÊÔ àµÍà 15 3. ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×é¹ Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔÈãµ ¡´ÊÇÔµª à¢Õ¹¤ Ò 255 (0xFF) ä»ÂѧÃÕ¨ÊÔ àµÍà 15 4. ÇÒ§âÁ´ÙÅ CMPS03 ¢¹Ò¹¡Ñº¾×é¹ Ëѹ´ ҹ˹ ҢͧâÁ´ÙÅä»·Ò§·ÔȵÐÇѹµ¡ ¡´ ÊÇÔµª à¢Õ¹¤ Ò 255 (0xFF) ä»ÂѧÃÕ¨ÊÔ àµÍà 15 ËÅѧ¨Ò¡»ÃѺᵠ§¤ ÒáŠǤ Ò·Õè»ÃѺᵠ§¨Ðà¡çºäÇ ·Õè˹ ǤÇÒÁ¨íÒÍÕÍÕ¾ÃÍÁ ´Ñ§¹Ñé¹áÁ äÁ ¨ ÒÂä¿ ãË ¡ºÑ µÑǺÍà ´ ¢ ÍÁÙÅ·Õ»è ÃѺᵠ§áÅ Ç ¨ÐÂѧ¤§ÍÂÙµ Í ä»
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
l
11
12
l
CMPS03 âÁ´ÙÅà¢çÁ·ÔÈ´Ô¨µÔ ÍÅ
ºÃÔÉÑ· ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔàÁ¹µ ¨íÒ¡Ñ´
3133/53 «.ÊØ¢ÁØ ÇÔ· 101/2 ¶. ÊØ¢ÁØ ÇÔ· á¢Ç§ºÒ§¹Ò ࢵºÒ§¹Ò ¡ÃØ§à·¾Ï 10260 â·ÃÈѾ· 0-2747-7001-4 â·ÃÊÒà 0-2747-7005
URL : www.inex.co.th
e-mail : tech@inex.co.th
µÑÇá·¹¨íÒ˹ Ò : ¾Õ.¾Õ. ¤ÍÁ¾ÔÇàµÍà 0-2226-4034, ÍÕàŤ·ÃÍ¹Ô¤Ê «Íà « 0-2623-9460-7, 0-2623-8364-6, ¹Ñ°¾§É à«ÅÊ á͹´ à«Íà ÇÊÔ 0-2225-0094, 0-2992-7379, E.D kit 0-2225-3282 àªÕ§ãËÁè : ¡ÔµµÔÍàÔ Åç¡â·Ã¹Ô¤Ê 0-5322-1463 ¹¤ÃÃÒªÊÕÁÒ : àÍÊ.«Õ ÍÔàÅç¡·ÃÍ¹Ô¡Ê 0-4424-3453 ÂÐÅÒ : SEP äÁâ¤Ãà·¤ 0-7324-7364 Order online : www.appsofttech.com ˹ ǧҹ¡ÒÃÈÖ¡ÉÒ : W&J àÍ繨Ôà¹ÕÂÃÔ§è 0-2943-9001-2