I'm new to arduino and I got an IO expander chip that uses SPI to communicate with the arduino but I am having a hard time making things work. I triple checked my hardware connections and there seems to be no fault. I followed the steps in the documentation for arduino SPI and came up with this code: ( The 1 second delay is added so that I can just view things slowly on the serial monitor)
<
I don't know if I have something wrong with my code or I'm not implementing things right but on the serial monitor I can see that I am getting 0s which is logical because I'm not pressing any button but if I do press the buttons, only the 12th button shows an output on the serial monitor and the rest don't. The buttons are connected from one side to +Vcc (5V) and the other side to the digital pins of the chip. I can't upload the datasheet of the chip as Im still a new user but it's M66006P by Mitsubishi. Any help is greatly appreciated
You state: "I got an IO expander chip that uses SPI to communicate with the arduino" That tells me you have one of many thousand different devices. My eyes are not what they need to be and I cannot see what you have even with my glasses. Posting a Schematic, not a frizzy thing with technical links to each piece of hardware will help.
Does the chip have built-in pull-down resistors? If not, you will need pull-down resistors (10k between chip input pin and Ground) to keep the pins from floating when they aren't connected to +5v.
The MCP23S17 is a 16 bit SPI port expander that has built in pullup resistors that can be enabled for each input. The MCP23S17 also has pin change interrupt capability that can be handy for reading switches.
yeahh, since I want to read 12 bits I'd rather use the transfer 16 which gives me 16 bits and just mask the unused 4 bits instead of transfer which gives me only 8 bits
I added pull down resistors but still nothing. I did notice that when I press on the button connected to D12 it does show an input on the serial monitor but it is not consistent with what I press and it does not read it every time.
The outputs/inputs per the data sheet are open drain. That tells us it has a n-channel fet driving it. Since there is nothing in the data sheet that I saw about pull ups, you need to add one to each I/O. Pull down resistors will not work. I believe you also have to set all the I/O to a logic 1 otherwise it will read its own "0" which is the dominate state. Let us know how you do. It is basically a pair of shift registers with serial in parallel out/parallel in/serial out )via SPI.
So I tried the pull up resistors and it did not work. I honestly feel like it's a big hassle and a waste of time and as frustrating as it is, to feel beaten by a chip, I have to move on with the project for the submission date so I ordered a different chip, PCF8574, and I got it up and running for 24 buttons 3 chips
Thanks to you and to everyone that gave this post a read and offered help