Multiple use of a port

A Due has 32bit ports. Is it possible to mix the use of the bits of the same port, e.g.

  • use some bits as input,
  • a further bit as an external interrupt,
  • and some further bits as output?

Every bit of a port can be defined as input or output. When writing data to a port then always 32 bits will be written.
If as an example bits 0...7 are defined as input and bits 15...19 as output, will then writing bits 15...19 also change bits 0...7?

I've never used the Due (or port addressing) and most of the time people are addressing individual pins without using or defining ports. The compiler takes care of that so you don't have to worry about what's happening at the hardware or machine language level.

digitalWrite(), analogWrite(), digtalRead(), and analogRead() all read/write one pin at a time.

Writing to a port data register changes only those bits designated as output. In other words, new data appears only on the pins designated as output pins.

If you are not convinced, that is something you can easily verify by doing an experiment.

This is not entirely true.

No.
Due's SAM3X controller use a pair of registers to control bits on output port - one to set the bits and another to clear.
Setting or clearing a bit in the output register is achieved by writing a one to the corresponding bit of the set or clear register. Bits set to zero are not affected.
This way you can control each bit individually without affecting other bits on the same port.

It seems to be a typical xy-problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.