Interplan IM920 library, 920MHz module

Dependents:   IM920_sample IM920_SDlog IM920_sample IM920_sample3 ... more

IM920 ライブラリ

データモード、低速、長距離 の設定で通信するライブラリです。

920MHz無線モジュール

http://www.interplan.co.jp/images/contents/solution/im920.png IM920 (インタープラン製)

  • mbedとモジュールとは、シリアル(TX,RX)、BUSY、RESET端子を接続します。
  • モジュールはあらかじめ、コマンドでノード番号などを設定しておきます。

NECの920MHz近距離無線モジュールもおすすめ

IM920_hal.cpp

Committer:
idealtechlab
Date:
2015-04-24
Revision:
5:2fd9b1725283
Parent:
3:db269462ad1c

File content as of revision 5:2fd9b1725283:

#include "IM920.h"

void IM920::setReset (bool flg) {
    if (_reset) {
        if (flg) {
            _reset->output();
            _reset->write(0);
        } else {
            _reset->input();
            _reset->mode(PullNone);
        }
    }
}

void IM920::isrUart () {
    recvData(getUart());
}

int IM920::getUart () {
    return _im.getc();
}

void IM920::putUart (char c) {
    _im.putc(c);
}

int IM920::lockUart (int ms) {
    Timer t;

    if (_busy && _busy->read()) {
        // CTS check
        t.start();
        while (_busy->read()) {
            if (t.read_ms() >= ms) {
                DBG("cts timeout\r\n");
                return -1;
            }
        }
    }
    return 0;
}

void IM920::unlockUart () {
}

void IM920::initUart (PinName busy, PinName reset, int baud) {
    _baud = baud;
    if (_baud) _im.baud(_baud);
    _im.attach(this, &IM920::isrUart, Serial::RxIrq);

    _busy = NULL;
    _reset = NULL;
    if (busy != NC) {
        _busy = new DigitalIn(busy);
    }
    if (reset != NC) {
        _reset = new DigitalInOut(reset);
    }
}