Creating and using a high speed 8-bit I/O bus

When working directly with DUE’s registers for high speed I/O, multiple threads have shown difficulty with reading inputs.

Before working with inputs, you need to ensure that the Parallel I/O Controller is enabled. To save power, the PIO controller automatically gets disabled if the port at any time is set as outputs.

Also, when updating any registers, I’ve had great success with working with register pairs.

Using PIOC, here’s some pseudocode to create, configure and control an 8-bit I/O port on pins 34 to 41.

REG_PMC_PCER0 |= 0x2000;              // PMC to enable Parallel I/O Controller C (PIOC, PID13)

uint32_t dataioPins = (0xFF << 2);    // mask for pins 34 to 41
byte readData, writeData;

REG_PIOC_ODR &= !dataioPins;
REG_PIOC_OER |= dataioPins;           // bus switched to output mode

REG_PIOC_CODR &= (0x00 << 2);         // bus cleared
REG_PIOC_SODR |= (writeData << 2);    // write bus pins

REG_PIOC_OER &= !dataioPins;
REG_PIOC_ODR |= dataioPins;           // bus switched to input mode

REG_PIOC_IFDR &= !dataioPins;
REG_PIOC_IFER |= dataioPins;          // enable input glitch filters

REG_PIOC_PUDR &= !dataioPins;
REG_PIOC_PUER |= dataioPins;          // enable pull up resistors

byte readData = REG_PIOC_PDSR >> 2;   // read bus pins