0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MSP430でPS/2-I2C変換

Last updated at Posted at 2025-04-06

とりあえずコミットしてみました。

割り込み処理で不整合が発生するのかI2C処理内でPS/2をいじると落ちるので、PS/2の処理はmainループで行っています。

使用したPS/2のライブラリは16Bitでキーコードを返してきて、下位・上位の順でI2Cのデータにしています。

FreeBSDのmrubyのbsdiicでこんな感じでいじれます。

MSPADDR = 0x4a

SETLED = 0
GETKEY = 1

t = BsdIic.new(0)

# NUM Lock LED On
t.write(MSPADDR, SETLED, 2)

usleep 100_000

loop do
  cur = t.read(MSPADDR, 2, GETKEY)
  if cur != nil && cur[0] != 0
    if cur[1] == 0 then
      print cur[0].to_s(16) + "\n"
    else
      print cur[0].to_s(16) + " " + cur[1].to_s(16) + "\n"
    end
  end
  usleep 10_000
end

ログはこれです。

15
15 80
1d
1d 80
24
24 80
2d
2d 80
2c
2c 80
35
35 80

接続したキーボードモジュールと相性があり、ときどき正常に起動しない事があります。キーボードモジュールは起動時に1バイトのデータを送ってくるので、それが受信できていないと起動に失敗しています。

mainループでLPMにしたいのですが、うまくできませんでした。またいつか調べます。

__delay_cycles()はintrinsics.hで定義されていて、引数はlong intなので32Bitです。これはlegacymsp430.hをincludeすると、in430.hがincludeされて、それが読み込みます。ヘッダーを読み込んでいないと、引数がintとして処理されて16Bitを超える直値を渡すとエラーになります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?