MCP23S08 SPI Problems

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Gypo
Posts: 52
Joined: Thu Apr 29, 2010 11:12 am
Has thanked: 5 times
Been thanked: 3 times
Contact:

MCP23S08 SPI Problems

Post by Gypo »

Hi

Has anyone got SPI working with a MCP23S08? Willing to help me out? Please.

I am trying to work out SPI stuff as I have several interfaces that need SPI communications but when I tried following the notes & circuits for the interfaces none worked. I have built many circuits but no joy.

So I thought I would just try a simple circuit first, get that working and then move back to the more intense stuff.

This is where I am at.
I am using a PIC18F4685 running with a 4Mhz crystal.
I have a RS232 chip connected to the USART TX & RX pins though at present I am not using that (it's built onto the board I have the PIC on).
I have a LED connected to RA0 and I flash this in the code just as a indication that something is happening.

I have the PIC18F4685 connected to the following MCP23S08 circuit (found in an application note somewhere)
Design1 - Schematic.jpg
MCP23S08 Circuit
(57.75 KiB) Downloaded 1620 times
Here is the Flowcode file
Flowcode1.fcf
PIC18F4685 Flowcode SPI File
(9 KiB) Downloaded 365 times
Anyone know why the Flowcode doesn't work?
The LED flashes but no matter what value I send to the port of the MCP23S08 the voltage on the port pins never changes.
The CS goes up and down and there is activity on the SI & SO pins (though I have only seen this using a digital multimeter not a scope (I don't have one).

Thanks for any help anyone can give, even a working project or example using a different PIC would be a great help. I have quite a few PICs so may be able to mimic your circuit).
Thanks for looking..

Regards Chris

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: MCP23S08 SPI Problems

Post by Benj »

Hi Chris,

First of all I would remove the initial "Make CS High" and "SPI Init" from the SPI_Send Macro and move to the start of the Main macro.

I would also get rid of the other "SPI Uninit" and "SPI Init" calls, these shouldn't be required.

Instead of calling the uninit function you will need to set the CS line high and maybe wait a few milliseconds before lowering again and doing the next command.

Example SPI_Send calls.

Make CS Low - 0 -> D2
SPI Send Char (0x40)
SPI Send Char (0x00)
SPI Send Char (0x00)
Make CS High - 1 -> D2
Delay 10ms
Make CS Low - 0 -> D2
SPI Send Char (0x40)
SPI Send Char (0x09)
SPI Send Char (0x00)
Make CS High - 1 -> D2
Delay 10ms
.....

I've not checked the hex values your sending but let us know how your getting on and I'll have another look at your next program if it still isnt working for you.

If you are fairly certain everything looks ok then you can try playing with the Clock polarity, Clock edge and Sample bit settings for the SPI component.

Gypo
Posts: 52
Joined: Thu Apr 29, 2010 11:12 am
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: MCP23S08 SPI Problems

Post by Gypo »

Benj

Thanks for a prompt reply with great wisdom.
What you said was spot on. I changed the code (attached) in line with your post and it worked.
I started to make changes to make it do what I need but then stopped before I made too many changes as I thought the file could be of use to others too.

I think the attached Flowcode file can be expanded upon by anyone to start testing and using SPI comms.
There is nothing fancy in it but without the help of Benj it would have taken me a whole lot longer to get it working, thanks Benj.
Flowcode1.fcf
Basic SPI to drive a MCP23S08
(8.5 KiB) Downloaded 375 times
Thanks again Benj
Regards
Chris

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: MCP23S08 SPI Problems

Post by Kenrix2 »

I am fairly certain the V4 SPI Legacy component will hyjack two port pins. Maybe the easiest way around this is to comment out* any lines in the SPI_Init with DAC_EN and FRM_EN in them using the custom code feature. It probably was put in the code for use with one of Matrix Multimedia's SPI modules.
* put // in the beginning of the line

Post Reply