I have an array of 8 sensors attached to my device ( a Fez PANDA II)
The information is returned as the amount of time the pin is high, and my sensors are connected to [P1.22…P1.29]
What I’d like to do is read the value of all of the pins in one go to process them.
Am I right in assuming that if I do this, it will work?
#define FIO1DIR (*(volatile unsigned long )(FIO_BASE_ADDR + 0x20))
#define FIO1MASK ((volatile unsigned long )(FIO_BASE_ADDR + 0x30))
#define FIO1PIN ((volatile unsigned long )(FIO_BASE_ADDR + 0x34))
#define FIO1SET ((volatile unsigned long )(FIO_BASE_ADDR + 0x38))
#define FIO1CLR ((volatile unsigned long *)(FIO_BASE_ADDR + 0x3C))
unsigned int Port1CurrentValues = FIO1PIN;
after which I can mask out the bits I’m looking for?
I also have another set of sensors attached to four different pins on the same port.
{ P1.1, P1.10, P1.8, P1.4}
In order to set up the sensor to deliver it’s values, I must set the pin high, wait 10 microseconds, and then set the pin low. I can then poll for the pulse train from the device.
is this pseudo code about right?
#define P0MASK = 1<<0;
#define P1MASK = 1<<1;
#define P2MASK = 1 << 2;
…
#define P31Mask = 1 << 31;
unsigned int pinMask = (P1MASK | P10MASK | P4MASK | P8MASK);
// ideally i’d like to disable interrupts here
FIO1DIR = FIO1DIR | pinMask;
// ideally i’d like reenable interrupts
FIO1SET= pinMask; // set my pins to output high.
// do additional work, and then wait for 10us timeout to expire as well.
FIO1CLR = pinMask; // set my pins output to low.
// ideally, I’d like to disable interrupts before the next line.
FIO1DIR = FIO1DIR & ~(pinMask); // set the port back to it’s previous io state.
// again, reenable interrupts
// now do work to process the response