How to add on digital IO pins to raspberry pi hardware using MCP23S17?

6 ビュー (過去 30 日間)
Frank0110
Frank0110 2015 年 2 月 6 日
コメント済み: Walter Roberson 2016 年 2 月 13 日
Hi,
I would like to add digital I/O pins to the raspberry pi hardware using the SPI of the MCP23S17.
There are already some tutorials for analog input using SPI with the MCP3008 and to add digital I/O Pins by I2C with the Matlab Support Package.
I'm looking forward an answer.
Best regards, Frank

回答 (1 件)

Greg Buffinton
Greg Buffinton 2016 年 2 月 11 日
編集済み: Greg Buffinton 2016 年 2 月 13 日
OK so after much trial and mostly error! ;)
this is what worked for me...
Registers:
CMD_READ = 65 % Device address + Opcode (ie Device 0 Read)
CMD_WRITE = 64 % Device address + Opcode (ie Device 0 Write)
GPIOA = 18
GPIOB = 19
GPPUB = 13 % Pullups for inputs
IOCON = 10
IODIRA = 0
IODIRB = 1
Commands
pi = raspi;
CE0 = spidev(pi, 'CE0');
writeRead(CE0,[CMD_WRITE IODIRA 0]); % Sets "A" port to outputs
writeRead(CE0,[CMD_WRITE GPIOA bin2dec('10101010')]); % Turns ON LED 7,5,3,1 and Turns OFF LED 6,4,2,0
writeRead(CE0,[CMD_WRITE GPPUB hex2dec('FF')]) % Enable pullups for port B inputs
writeRead(CE0,[CMD_READ GPIOB 0]) % read inputs. Note these may be inverted.
writeRead(CE0,[CMD_WRITE IPOLB bin2dec('11111111')]) % invert polarity in bitmask
writeRead(CE0,[CMD_READ GPIOB 0])
Make sure you send dummy bytes when reading!
Helpful snippets:
And
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 2 月 13 日
What an odd I/O system. I wonder why it was thought to be a good idea?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Raspberry Pi Hardware についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by