CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Mcp23s17

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

Mcp23s17
PostPosted: Mon Nov 27, 2017 2:05 pm     Reply with quote

Hello, I would like to use interrupt outputs. Everything is running fine but I would like to interrogate inputs at interrupt instead of cyclic. I did not understand anything in the instructions. Has any experience that could give me tips ?
greeting
temtronic



Joined: 01 Jul 2010
Posts: 9249
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 27, 2017 2:45 pm     Reply with quote

When posting questions like this, please add a 'link' to the device.
OK, I downloaded the datasheet and it's a 2 port, I2C expander.
It's actually quite powerful, with YOU in charge of which pins cause an interrupt. You simply have to send that data to the device as well as active high or active low that 'triggers' the interrupt. Also you need to decide what kind of interrupt - open drain (where several devices are on the same INT bus) or discrete (1 device = 1 INT pin).
It may be that CCS has an example but it's not in my old version of the compiler.
I can't cut code and say 'here it is', as I need to have the hardware to confirm my code works.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19557

View user's profile Send private message

PostPosted: Mon Nov 27, 2017 2:53 pm     Reply with quote

There is a standard driver for this with the compiler.
Has been for about 10 years!.
It allows you to write and read the individual registers. However interrupt use requires you to setup the patterns for this.

The big question is what type of interrupt is wanted?

You can have a single interrupt output from each bank, or a combined output from both. This can be active high, low or open collector.
You can set each pin to interrupt on change, or when they differ from a defined level.
Obviously when this trigger the PIC interrupt handler would have to read the port, or it can read what pattern was on the port when the interrupt fired (this is stored for you).
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Mon Nov 27, 2017 9:36 pm     Reply with quote

It should be a normal interrupt. If the state of a port changes then it should give me a high or low signal so I can query on spi which of the inputs has triggered, or is there another alternative? Constantly polling would only be time consuming, I think. It is said register Gpinten enables the interrupt. I do not understand what that has with Defval and Intcon register on it.
Greeting
Ttelmah



Joined: 11 Mar 2010
Posts: 19557

View user's profile Send private message

PostPosted: Mon Nov 27, 2017 11:45 pm     Reply with quote

OK.

GPINTEN, is like the TRIS. You put into it a pattern of bits, with a '1' for every input you want to have an interrupt on. So if you want to use the interrupt on pins A0 and A1, you load GPINTENA with 0x03.

For a standard interrupt on change, you can then leave INTCONA and B both set as 0.

If you then leave MIRROR, ODR and INTPOL all set as 0, you will get the INTA output dropping when the selected pins change.

When this triggers:

You can read the INTFA register which will tell you which bit(s) have triggered.
The INTCAP register will hold a copy of the complete port at the moment the interrupt triggered.

Reading the port, will clear the interrupt.
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

Done
PostPosted: Tue Nov 28, 2017 11:00 am     Reply with quote

Thank you for the tip. I was already on the right track. My biggest mistake was that I forgot a LOW-signal during initialization of SPI because of this written in total other registers. Without your tip, I would not have got further. Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group