EdisonのMraa(SPI)を使う

EdisonのMraaを使い、Python言語でSPIの設定を行ってみた。

Arduino Boardでは
IO10:SPI_2_SS1(CS)
IO11:SPI_2_TXD
IO12:SPI_2_RXD
IO13:SPI_2_CLK
が使える。

Pythonで以下のコマンドが使える。

Spi (int bus)
mode (Spi_Mode mode)
frequency (int hz)
writeByte (uint8_t data)
write_word (uint16_t data)
write (uint8_t *txBuf, int length)
write_word (uint16_t *txBuf, int length)
transfer (uint8_t *txBuf, uint8_t *rxBuf, int length)
transfer_word (uint16_t *txBuf, uint16_t *rxBuf, int length)
lsbmode (bool lsb)
bitPerWord (unsigned int bits)

SPI_MODE0
CPOL = 0, CPHA = 0, Clock idle low,
data is clocked in on rising edge,
output data (change) on falling edge

SPI_MODE1
CPOL = 0, CPHA = 1, Clock idle low,
data is clocked in on falling edge,
output data (change) on rising edge

SPI_MODE2
CPOL = 1, CPHA = 0, Clock idle low,
data is clocked in on falling edge,
output data (change) on rising edge

SPI_MODE3
CPOL = 1, CPHA = 1, Clock idle low,
data is clocked in on rising,
edge output data (change) on falling edge

注意点
frequency()はHzで指定 25MHzまで
SpiのSは大文字で書く
Spi()のポート番号はなんでもいいみたい。。。?? 1、2でも同じ動き。
mode()は0,1,2,3を指定。
lsbmode()は、数字を入れるとエラーになるし、うまく動かない。???

使用例

#!/usr/bin/python

import mraa

spi = mraa.Spi(2)
spi.frequency(1000000)
spi.mode(0)
spi.lsbmode(True)

while True:
spi.writeByte(0x35)

受信は、まだやってないです。。。

“EdisonのMraa(SPI)を使う” への5件のフィードバック

  1. Woah! I’m really digging the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s tough to get that “perfect balance” between user friendliness and visual
    appearance. I must say you’ve done a superb job with this.

    Also, the blog loads extremely quick for me on Chrome.
    Outstanding Blog!

  2. Excellent beat ! I would like to apprentice whilst you amend your web site, how can i subscribe
    for a blog site? The account aided me a acceptable deal.
    I have been tiny bit acquainted of this your broadcast
    provided bright clear concept

  3. Have you ever thought about creating an e-book or guest authoring on other websites?
    I have a blog based upon on the same ideas you discuss and would love to have you share some stories/information. I know my readers would
    enjoy your work. If you’re even remotely interested,
    feel free to send me an email.

  4. Having read this I thought it was very informative.
    I appreciate you spending some time and energy to put
    this short article together. I once again find myself personally spending way too much time both reading and leaving
    comments. But so what, it was still worthwhile!

  5. It’s actually a cool and helpful piece of information.
    I’m glad that you simply shared this helpful information with us.
    Please keep us up to date like this. Thank you for sharing.

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>