forbiddenera
Well-known member
Thought I'd make a new thread since this is sort of a separate issue and since my original thread my project might not even be using DMA, heh..
edit: I maybe figured out the GPIO_GDIR part, I think it actually turned out to be a quirk in my testing setup not an issue of manipulating that register.
I'm using GPIO6.16-30 to read a parallel memory address from pins, making an 27c256 EPROM emulator (trying). My other thread has more background information if needed. Reading is fine (access bits 16-30 of GPIO_DR)..
I need to switch either GPIO6.16-31 to input/output rather quickly or alternatively switch 8 pins on say, GPIO2/7 to HI-Z/output.
My target device shares address pins 0-7 with the data pins using a latch. Once I've read the address and OE# has been triggered, I want to switch the pins to output and output the required data. This needs to happen very quickly, thus me wanting to directly access the register to modify the direction in one swoop.
As far as I can tell from the manual, in the GPIOn_GDIR register, 0-31 maps to inputs 0-31 of each GPIO. Thus bits 16-31 should control the directions of those pins.
Reading back the register, I get the bits set that I expect, 16-31 set to 1. When this happens, even though I set the address to input first, I get garbage in readAddress.. Not sure if I need to wait or something?
Also, once GPIO_GDIR is set back to zero, bits 21-25, and 27-31 wouldn't respond, IE, if all pins are pulled high I should get 1111 1111 1111 111x back from the register (last bit=don't care), but I get back 1111 0000 1111 0000 instead, even if all of GPIO_GDIR is set to 0's as it originally was..?
Today with testing, I'm getting back 1111 0000 1111 0010 .. which feels even weirder?! I should note that, this is also in the main loop() -- I could see possibly getting garbage back from reading GPIO_DR right after setting back to input in the ISR at least and maybe having to wait - but the main loop() which cycles at 100ms still reads 1111 0000 1111 0010 several loops later, so something isn't getting set right.
I've also noticed that, after uploading, sometimes (not always), if all pins are set to high, I get back the same sort of response until the pins go low and high again - this is *without* triggering the OE# pin / thus triggering the ISR.
Any ideas on what I'm missing? Does simply changing GDIR affect anything in the MUXC? Do I need to set some other stuff? Is there a better way to do this? Again, I'm simply looking to read those pins then quickly turn them to outputs or at least be able to change 8 other pins quickly from output to HI-Z. Ideally I'd like to do both for different projects, either should be possible.
edit: I maybe figured out the GPIO_GDIR part, I think it actually turned out to be a quirk in my testing setup not an issue of manipulating that register.
I'm using GPIO6.16-30 to read a parallel memory address from pins, making an 27c256 EPROM emulator (trying). My other thread has more background information if needed. Reading is fine (access bits 16-30 of GPIO_DR)..
I need to switch either GPIO6.16-31 to input/output rather quickly or alternatively switch 8 pins on say, GPIO2/7 to HI-Z/output.
My target device shares address pins 0-7 with the data pins using a latch. Once I've read the address and OE# has been triggered, I want to switch the pins to output and output the required data. This needs to happen very quickly, thus me wanting to directly access the register to modify the direction in one swoop.
As far as I can tell from the manual, in the GPIOn_GDIR register, 0-31 maps to inputs 0-31 of each GPIO. Thus bits 16-31 should control the directions of those pins.
Code:
unsigned GDIR_MASK = 0xFFFF0000;
void pinChangeISR() {
register long unsigned ISRstart = ARM_DWT_CYCCNT;
if (OEstate == LOW) {
// GPIO6_GDIR &= ~GDIR_MASK; //clear (set pins to input)
readAddress = (GPIO6_DR >> 16);
OEstate = HIGH;
} else {
OEstate = LOW;
// GPIO6_GDIR |= GDIR_MASK; //set (set pins to output)
}
Reading back the register, I get the bits set that I expect, 16-31 set to 1. When this happens, even though I set the address to input first, I get garbage in readAddress.. Not sure if I need to wait or something?
Also, once GPIO_GDIR is set back to zero, bits 21-25, and 27-31 wouldn't respond, IE, if all pins are pulled high I should get 1111 1111 1111 111x back from the register (last bit=don't care), but I get back 1111 0000 1111 0000 instead, even if all of GPIO_GDIR is set to 0's as it originally was..?
Today with testing, I'm getting back 1111 0000 1111 0010 .. which feels even weirder?! I should note that, this is also in the main loop() -- I could see possibly getting garbage back from reading GPIO_DR right after setting back to input in the ISR at least and maybe having to wait - but the main loop() which cycles at 100ms still reads 1111 0000 1111 0010 several loops later, so something isn't getting set right.
I've also noticed that, after uploading, sometimes (not always), if all pins are set to high, I get back the same sort of response until the pins go low and high again - this is *without* triggering the OE# pin / thus triggering the ISR.
Any ideas on what I'm missing? Does simply changing GDIR affect anything in the MUXC? Do I need to set some other stuff? Is there a better way to do this? Again, I'm simply looking to read those pins then quickly turn them to outputs or at least be able to change 8 other pins quickly from output to HI-Z. Ideally I'd like to do both for different projects, either should be possible.
Last edited: