Port groups and interrupts

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
qubit
Posts: 3
Joined: Sun May 24, 2015 8:46 pm

Port groups and interrupts

Post by qubit » Sun Aug 02, 2015 11:54 am

Hi

Quite new to this micro python board and like it quite a bit. I was wonder if someone could shed some light on my issue.

I have a group of hall sensors that I have on a motor and need to get their value each time one of them is triggered by interrupt. If the pin itself is an interrupt I can tell which pin triggered the interrupt for that pin but not as a group value. Is it possible to set the interrupt on a port level and then read their values rather than a pin level.

For example, I use pin X1, X2, X3 and they are all on port 1. What I am trying to do is if port 1 detects an interrupt then I read all the pin values for X1, X2 and X3.

Thanks

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Port groups and interrupts

Post by dhylands » Sun Aug 02, 2015 4:37 pm

The stm32f4 processors don't have a notion of "port changed".
It only has a restricted sense of pin changed. You can watch for a particular pin changing, but you can only watch a single pin 0, and a single pin 1.

So you can watch D0 and C2, but you can't watch D2 and C2.

For your example, you can use the ExtInt (http://docs.micropython.org/en/latest/l ... xtInt.html) module to watch for a pin change on any of the 4 pins (Since X1 thru X4 are mapped to pins A0 thru A3.

The only way to read all 4 values at once is to use the stm module. You could do:

Code: Select all

import stm
val = stm.mem16[stm.GPIOA + stm.GPIO_IDR] & 0x0f

qubit
Posts: 3
Joined: Sun May 24, 2015 8:46 pm

Re: Port groups and interrupts

Post by qubit » Mon Aug 03, 2015 10:30 pm

Thanks dhylands. I was hopefully trying to stay as python(y) as possible but I suspect I can't avoid the lower level stuff completely.

Post Reply