Changes between Version 1 and Version 2 of epics/bbb/debian/thermometer/ft260


Ignore:
Timestamp:
09/05/17 17:58:43 (8 years ago)
Author:
Tetsuya Michikawa
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • epics/bbb/debian/thermometer/ft260

    v1 v2  
    6060となり、I2Cのみになるので、これで実験することにする。
    6161
    62 
     62== pythonでのテスト ==
     63
     64以前、帯名さんがHIDデバイスのテストをした時のドキュメントを参考にしてみる。[[br]]
     65まずは、FT260の設定を取得してみる。
     66
     67{{{
     68oot@beaglebone:~# ipython --nosep
     69Python 2.7.9 (default, Aug 13 2016, 17:56:53)
     70Type "copyright", "credits" or "license" for more information.
     71
     72IPython 2.3.0 -- An enhanced Interactive Python.
     73?         -> Introduction and overview of IPython's features.
     74%quickref -> Quick reference.
     75help      -> Python's own help system.
     76object?   -> Details about 'object', use 'object??' for extra details.
     77In [1]: import hid
     78In [2]: h = hid.device()
     79In [3]:
     80In [3]: h.open(0x0403, 0x6030)
     81In [4]: h.set_nonblocking(1)
     82Out[4]: 0
     83In [5]: h.write([0xA1] + [0]*63)
     84Out[5]: 64
     85In [6]: h.read(64)
     86Out[6]: []
     87In [7]: h.write([0xA0] + [0]*63)
     88Out[7]: 64
     89In [8]: h.write([0xA0] + [0]*63)
     90Out[8]: 64
     91In [9]: h.read(64)
     92Out[9]: []
     93In [10]: h.write([0xA0] + [0]*11)
     94Out[10]: -1
     95In [11]: h.write([0xA0] + [0]*63)
     96Out[11]: -1
     97In [12]: h.read(64)
     98Out[12]: []
     99In [13]: h.read(64)
     100Out[13]: []
     101In [14]: h.write([0xA0] + [0]*63)
     102Out[14]: -1
     103In [15]: h.write([0xC0] + [0]*63)
     104Out[15]: -1
     105In [16]: h.close()
     106}}}
     107
     108うまくいかない、、、[[br]]
     109色々見ていったところ、取得するデータによって使用する関数が違うらしい。[[br]]
     110[http://www.ftdichip.com/Support/Documents/ProgramGuides/AN_394_User_Guide_for_FT260.pdf FT260のアプリケーションノート]を見てみると、15ページの{{{4.3 FT260 Report ID List}}}には、
     111
     112
     113|| Report ID || Type || description ||
     114|| 0xA0 || Feature || Chip code ||
     115|| 0xA1 || Feature || System Setting ||
     116|| 0xB0 || Feature || GPIO ||
     117|| 0xB1 || Input   || Interrupt Status (from UART interface) ||
     118|| 0xC0 || Feature || I2C Status ||
     119|| 0xC2 || Output  || I2C Read Request ||
     120|| 0xD0 ~ 0xDE || Input, Output|| I2C Report ||
     121|| 0xE0 || Feature || UART Status ||
     122|| 0xE2 || Feature  || UART RI and DCD Status ||
     123|| 0xF0 ~0xFE ||Input, Output || UART Report ||
     124
     125と書いてあり、{{{Feature}}}へのアクセスは{{{send_feature_report, get_feature_report}}}で行い、{{{INPUT,OUTPUT}}}は{{{write,read}}}で行うらしい。
     126
     127
     128{{{
     129root@beaglebone:~# ipython --nosep
     130Python 2.7.9 (default, Aug 13 2016, 17:56:53)
     131Type "copyright", "credits" or "license" for more information.
     132
     133IPython 2.3.0 -- An enhanced Interactive Python.
     134?         -> Introduction and overview of IPython's features.
     135%quickref -> Quick reference.
     136help      -> Python's own help system.
     137object?   -> Details about 'object', use 'object??' for extra details.
     138In [1]: import hid
     139In [2]: h = hid.device()
     140In [3]: h.open(0x0403, 0x6030)
     141In [4]: h.get_feature_report(0xA0,13)
     142Out[4]: [160, 2, 96, 2, 0, 2, 96, 1, 0, 1, 1, 3, 0]
     143In [5]: h.get_feature_report(0xA1,64)
     144Out[5]:
     145[161,
     146 1,
     147 2,
     148 0,
     149 1,
     150 1,
     151 0,
     152 0,
     153 1,
     154 3,
     155 6,
     156 1,
     157 1,
     158 12,
     159 1,
     160 0,
     161 0,
     162 0,
     163 0,
     164 0,
     165 172,
     166 0,
     167 188,
     168 0,
     169 204]
     170}}}
     171
     172これでやっと、FT260にアクセスできることが確認できた。[[br]]
     173次にI2C上のスレーブデバイスにアクセス。[[br]]
     174
     175接続しているI2Cデバイスは、[http://www.analog.com/jp/products/analog-to-digital-converters/integrated-special-purpose-converters/digital-temperature-sensors/adt7410.html#product-overview ADT7410]を基板化した、[http://akizukidenshi.com/catalog/g/gM-06675/ 秋月電子 ADT7410使用 高精度・高分解能 I2C・16Bit 温度センサモジュール]。
     176
     177FT260開発ボードの3.3V電源と、IO0,IO1を接続した。
     178
     179{{{
     180FT260        <->  ADT7410
     1813.3V (JP6-1)       VDD
     182IO0 (JP6-11)       SCL
     183IO1 (JP6-10)       SDA
     184GND                GND
     185}}}
     186
     187温度センサのI2Cアドレスは0x48としておく。
     188
     189{{{
     190In [1]: import hid
     191In [2]: h = hid.device()
     192In [3]: h.open(0x0403, 0x6030)
     193In [4]: h.set_nonblocking(1)
     194Out[4]: 0
     195In [5]: h.write([0xC2, 0x48, 0x06, 0x04, 0x00])
     196Out[5]: 5
     197In [6]: h.read(64)
     198Out[6]: [208, 4, 13, 88, 128, 0, 50, 0]
     199}}}
     200
     201先頭2byteはFT260のHIDコマンドヘッダなので、{{{[13, 88, 128, 0, 50, 0]}}}がデータ。[[br]]
     202取得するデータ数は4byteだけど、6byteデータが出てくる。多分、HIDヘッダも含めて4byte単位でデータが出てくるのだろう。[[br]]
     203
     204ADT7410のデータシートから、{{{[13, 88]}}}が温度データ、次の{{{[128]}}}がStatus、{{{[0]}}}がConfigurationとなっているようだ。[[br]]
     205Configurationの7bit目が1なら16bit,0なら13bitデータになる。[[br]]
     20613bit時のデータは[15:3]が有効なデータなので、計算式は、
     207
     208{{{
     209ADC_DEC = ((HSB<<8) | LSB)>>3
     210
     211Positive_Temp[℃] = ADC_DEC /16.0
     212Negative_Temp[℃] = (ADC_DEC - 8192)/16
     213}}}
     214
     215となるらしい。[[br]]
     216この計算式に当てはめると、{{{LSB=88,HSB=13}}}の場合、{{{26.6875[℃]}}}となる。[[br]]
     217
     218今回は16bitで使いたいので、Configration Registorの7bit目を1にする必要がある。[[br]]
     219
     220
     221