Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Code for MCP23S17 interface with PIC16F877A

Status
Not open for further replies.

gomathig

Newbie level 5
Joined
May 14, 2009
Messages
10
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,344
mcp23s17 example

If any one have sample code for MCP23S17 interface with PIC16F877A using MPLAb IDE or other compiler tool. Kindly send.
 

mcp23s17

Hi gomathig,

I’ve never done PIC before, but I think that if you have even the slightest idea about what uC, SPI, ASM and C means, besides being letters in the alphabet, you’d be able to “write” (read “copy”) all the code you need in no time.

Microchip’s web site is bursting with application notes and code snippets, so I wonder why won’t you consume 0.7 of you own calories and look there for an SPI example (which is btw. the way of interfacing the 2 chips you mentioned).

Because I don’t want to believe you really are so lazy, I will assume that your finger hurts and you’d like to limit the number of mouse clicks to a minimum. Click once here then: **broken link removed**
I’m afraid you’d need two more clicks to download the source code.

If you substitute the EEPROM in the example with your MCP23S17 (and maybe read its datasheet…) you’re all done without breaking a sweat!

Arthur
 

mcp23s17 code

Hi gomathig,

I think it will be good to try out some coding on your own.
When you encounter some technical issue,
this is a good place for you to ask and learn.
There are many many experience friends here to help us.

In fact if you need the code, there are many
site which source is available. From microchip perhaps.

If you come to forum, my mentality is that you really
want to learn something from here.

A source code example would be good to start with,
but most of the time I will normally use it as it is, and didn't learn anything.
Give it a try on SPI , you will learn more which is a useful experience
for other area, not only in SPI (although you are doing SPI).
 

mcp23s17 application

I Have tried to interface PIC16F877A with MCP23S17 in MPLAB, but still i am not getting the result. I have specified my code please check it out below and tell me to do futher process.



#include<pic.h>
#include<stdio.h>
#include "delay.c"

__CONFIG(0x3f72);

#define IODIRA 0x00
#define IODIRB 0x01
#define IOCONA 0x0A
#define GPPUA 0x0C
#define GPIOA 0x12
#define READ 0X41
#define WRITE 0X40

#define CS RC1
#define MOSI RC5
#define MISO RC4
#define SCK RC3
void spi_init(void);
void spi_write(unsigned char);
void InitMCP();
//unsigned char i;

void main()
{
spi_init();
InitMCP();
while(1)
{
TRISD = 0X00;
PORTD = 0X01;
DelayMs(20);
DelayMs(20);
PORTD = 0X02;
spi_write(0x01);
DelayMs(20);
/*for(i=1;i<=8;i++)
{
spi_write(i);
} */
}
}
void spi_init()
{
TRISC = 0XD1;
SSPSTAT = 0X40;
SSPCON = 0X20;
PORTC = 0X02;
}
void InitMCP()
{
CS=0;
SSPBUF = WRITE;
while(BF==0);
SSPBUF = IOCONA;
while(BF==0);
SSPBUF = 0x54;
while(BF==0);
SSPBUF = IODIRA;
while(BF==0);
SSPBUF = 0X00;
CS=1;
}
void spi_write(unsigned char data)
{
CS=0;
SSPBUF = WRITE;
while(BF==0);
SSPBUF = GPIOA;
while(BF==0);
SSPBUF = data;
while(BF==0);
CS=1;
}
 

mcp23s17 sample code

Hi,

Read up on the datasheet to enable that you have all the bits
correctly enabled. Understand what each bit is trying to do.
The datasheet is pretty well written.
Follow the step by step guide should do.

Perhaps you can start writing a write() function.
Check if there is any output signal from the controller pin,
after the write is issued.
If not, ensure that you have set the bits correctly.

Make sure you can write before your read,
because it is easier to write.

Best Regards,
Siong Boon
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top