Reading 8 GPIO simultaneously

I’m trying to hack an 8-bit data line

Is there an 8-bit digital registry that can read 8 GPIOs status at exactly the same time?

Next question is what’s the fastest sampling rate that Dash can reliably extract from the 8-bit line?

The easiest way to do that would be to use pins PTD0-PTD7, configure them as inputs, and read them via:

GPIOD_PDIR & 0xFF;

Those correspond to Dash pins:
R16, L05, L06, L08, R04, L07, R05, R03

The GPIO pins run off the system clock, which is 120MHz if you are running the default max speed. I couldn’t find an explicit answer in the datasheet, but you should be able to run in the MHz range easily (SPI can run at 25MHz I believe). You may need to look at DMA (which is available but we don’t currently support) for tight timing constraints. You could also explore the FlexBus, which is a configurable hardware IO device. It is documented in Chapter 31 of the processor Reference Manual.

Thanks very much Erik as always.
BTW, where can I learn those hidden commands/calls such as GPIOD_PDIR & 0xFF;

This is the processor reference manual:

http://cache.nxp.com/docs/en/reference-manual/K22P64M120SF5V2RM.pdf?fsrch=1&sr=1&pageNum=1

It lists all of the registers.

From the Arduino code package, the file MK22F51212.h has all the C language definitions for the registers.

Great help Erik. Can’t thanks enough.

Hi Erik,

I implemented the code as below:

#define LCD0 R16         // JTAG Connector
#define LCD1 L05         // JTAG Connector
#define LCD2 L06         // JTAG Connector
#define LCD3 L08         // JTAG Connector
#define LCD4 R04         // JTAG Connector
#define LCD5 L07         // JTAG Connector
#define LCD6 R05         // JTAG Connector
#define LCD7 R03         // JTAG Connector

void setup() {
Serial.begin(115200);
pinMode(LCD0, INPUT_PULLUP);
pinMode(LCD1, INPUT_PULLUP);
pinMode(LCD2, INPUT_PULLUP);
pinMode(LCD3, INPUT_PULLUP);
pinMode(LCD4, INPUT_PULLUP);
pinMode(LCD5, INPUT_PULLUP);
pinMode(LCD6, INPUT_PULLUP);
pinMode(LCD7, INPUT_PULLUP);

void loop() {
Serial.println(GPIOD_PDIR & 0xFF);
}

I’m getting values from 75 to 255. If this is normal, then how can I convert this to 8-bit binary? Is the result OCTAL?

Sorry for asking too soon… I found it’s octal and I just printed it as:

Serial.println(GPIOD_PDIR & 0xFF, 2);

This gives expected results:

void loop() {
  uint8_t input = GPIOD_PDIR & 0xFF;
  Serial.print(input, HEX); 
  Serial.print(" ");
  Serial.println(input, BIN);
  delay(1000);
}

If you ground each pin individually you can see the values change as expected. I’m not sure if you want the PULLUP setting on the input pins or not. Depends on the driving hardware and if you want default-1 (versus default-0), or just leave it floating.

Thanks Erik for the code. In my case, I need to have default-1 so I used PULLUP.

Excellent! We’d love you to post an update when you get it all working. Good Luck.

@Erik, The 8-bit data acquisition code works. The conversion from OCTAL to BINARY also works except that MSB is not padded when value is 0 (ex.: 75) as shown below :

214: 11010110
240: 11110000
206: 11001110
255: 11111111
75: 1001011
255: 11111111
255: 11111111
255: 11111111
206: 11001110
206: 11001110
255: 11111111
206: 11001110
236: 11101100
206: 11001110
206: 11001110
75: 1001011
206: 11001110
206: 11001110
255: 11111111

I’m also debugging an issue that affected the pulseIn() command in the same code block. This command is functional before I rewired the board. pulseIn() is using R03 AND R04 before and I already transfered it to other pins without success yet. Can you give me pins which works well to detect HIGH side pulse detection?

1 Like

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)