MCP23S17 I/O Expansion
anti-hero
Posts: 8
I've been trying to get the MCP23S17 working. Just trying to turn on LED's for now, but notta lotta success!
Here's my code:
CS PIN 0 'chip select pin 11 MCP23S17
SCK PIN 1 'serial clock pin 12 MCP23S17
SI PIN 2 'serial in pin 13 MCP23S17
SO PIN 3 'serial out pin 14 MCP23S17
LOW CS 'opcode,register,data
SHIFTOUT SI,SCK,MSBFIRST, [noparse][[/noparse]%01000000,$00,%00000000] 'make 'em all outputs IODIRA register
HIGH CS
LOW CS 'opcode,register,data
SHIFTOUT SI,SCK,MSBFIRST, [noparse][[/noparse]%01000000,$0A,%01010000] 'setup IOCON register
HIGH CS
LOW CS 'opcode,register,data
SHIFTOUT SI,SCK,MSBFIRST, [noparse][[/noparse]%01000000,$12,%11111111] 'turn on outputs GPIOA register
HIGH CS
Any idea why its not workin?
Thanks in advance.........
Here's my code:
CS PIN 0 'chip select pin 11 MCP23S17
SCK PIN 1 'serial clock pin 12 MCP23S17
SI PIN 2 'serial in pin 13 MCP23S17
SO PIN 3 'serial out pin 14 MCP23S17
LOW CS 'opcode,register,data
SHIFTOUT SI,SCK,MSBFIRST, [noparse][[/noparse]%01000000,$00,%00000000] 'make 'em all outputs IODIRA register
HIGH CS
LOW CS 'opcode,register,data
SHIFTOUT SI,SCK,MSBFIRST, [noparse][[/noparse]%01000000,$0A,%01010000] 'setup IOCON register
HIGH CS
LOW CS 'opcode,register,data
SHIFTOUT SI,SCK,MSBFIRST, [noparse][[/noparse]%01000000,$12,%11111111] 'turn on outputs GPIOA register
HIGH CS
Any idea why its not workin?
Thanks in advance.........
Comments
I had some success using the MCP23S17 but subsequently I abandoned it, updated to the BS2P which is not only faster but has some built in LCD stuff.
I wanted to find a way to write to an LCD with fewer IO lines in one of my BASIC STAMP projects. I stumbled across a board on EBAY that used the MCP23S17 and thought it would be a good start. The supplier of the board indicated that it could be used with the Basic Stamp and included sample code. It could but the sample code it came with was NOT for the Basic Stamp. Oh well. I had to figure it out myself.
I got it all working but it was really slow with all the MCP23S17 overhead. I don't use it any longer. For normal IO stuff that is not speed sensitive, I would be fine.
My application was a speedometer for use on my "rideable" 1/6 scale locomotive. This is the scale that is used commonly in the "Live Steam" hobby. I gather a variety of data from my locomotive and display it on the "Engineers Control Panel"
The card would receive a string of serial commands and/or directly sample various pieces of data and display them on a 2 X 16 Backlit LCD in my handheld contrller.
The heart of the program is the part that sends data to the 23s17 and is clearly annotated. Sorry for any stupid typos. I did not try to clean this code up for anyone... It is just the notes I took for myself when I wrote it.
There is a section where I wrote MPH VAC AMP PSI to the display. These were static labels for the values I wanted to display.
I believe in this version I used the sub routing speedo_raw to count pulses on a sprocket to determine MPH on my train. It took too long to write to the display and do the COUNT function so I moved on to another method of writing to the LCD. It doesn't look like I ever implemented the serin comands for the other data. Clearly I ran out of CPU time at this point and moved on to other methods.
HOWEVER the code is attached for anyone that is interested. This was a while ago and I am not sure I can answer questions intelligently, but I will try.
Greg
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
AUTOMATE EVERYTHING
http://www.trainyard.net
I hooked up 8 LEDs using 470 ohm resistors on each pin on Port B and wrote a program to alternate lighting every other LED.
It works for a while and then just stops. The program continues to loop but the MCP23S17·does not respond.
I tried a different MCP23S17 IC, and it acts the same.
I am using a 9 volt 1 amp power supply so it's not a battery issue. The chip does not get warm and I'm sure each LED is drawing less than 25mA, so I can't figure out what is going on. Using OLATB gives the same result as using GPIOB
I have used a MCP23016 (I2C) and had no problem.
Here is my code - any help would be appreciated!!
Post Edited (Ron Czapala) : 7/17/2010 10:31:36 PM GMT
I just noticed that rubbing the wooden desktop within a few inches of the breadboard causes the MCP23S17 to quit working.
The humidity level is not too dry but I wonder if there should be some capacitors on the SI, SO,·SCK, CS pins???
Video http://www.youtube.com/watch?v=JDQhNROvy8Q
I've been continuing my testing and it seems to be a timing issue. I even tried using the MCP23017 I2C version with both a BS2 and BS2P Stamp.
It works for a while and then quits. I am attaching a version which writes to the GPIOB register at intervals of 500, 400 and 300 milliseconds (50 times each). It seems to work OK. I change it to include 200 millisecond interval, it fails.
I think I'll stick to the MCP23016 -seems more reliable.
·NOTE - I switched to different BS2 pins in this version
Post Edited (Ron Czapala) : 7/18/2010 4:04:26 AM GMT
Anyone else using the MCP23S17, be sure to connect pin 18 RESET to +5V if you're not using it externally. Also, pins 15,16,17 connect to GND. I wasn't sure about using the reset but I tested it this way and it works. Datasheets are not always crystal clear about everything!
SI and SO pins 13 and 14 can be tied together with a 470ohm resistor and use one stamp pin.
Thanks again for the help....
·
·· I'm glad you pointed out that the RESET pin needed to be connected.
I missed the datasheet saying "Hardware reset. Must be externally biased."
I'm pretty sure this solves my issue with the IC not responding!
- Ron
PS.· I found a MicroChip evaluation board document that indicated a .01 uf decoupling cap should be used across the VDD VSS pins.
Post Edited (Ron Czapala) : 7/19/2010 5:02:04 PM GMT
It's also important to have bypass capacitors, usually a 0.1uF ceramic capacitor between Vdd and Vss close to the chip. A well designed board will have one of these for every chip, particularly complex chips. You also need a larger, maybe 10uF tantalum capacitor near where the power enters the board.
You mentioned that SI and SO can be connected together (in another MCP23S17 thread) and anti-hero said he connected them together with a 470 ohm resistor.
Where did you find that tid-bit? I have seached all over and never found any info like that.
These forums are a great for researching circuits, sensors, etc
Thanks!
The program reads the GPIOA register to check whether a switch button was pushed. The button on GPA7 was not being detected.
Reading other register values did not work well either.
I discovered that using separate connections from the SI and SO pins to the BS2 (rather sharing a pin between SI and SO·with a·resistor) fixed the problem.
I would NOT RECOMMEND connecting SI and SO to save a BS2 pin.
Post Edited (Ron Czapala) : 7/22/2010 1:58:27 PM GMT
· I had the resistor connected as you described, but reading registers returned incorrect values.
I think it is a timing concern trying to do a Shiftin immediately after a Shiftout on the same BS2 pin.
The following code returned the correct value only after I switched back to separate BS2 pins for SI and SO.