Port register usage

I want to do 8 bit parallel digital out into a D/A converter (in one operation).

I was reading the port reference: http://www.arduino.cc/en/Reference/PortManipulation

If I read this correctly, is there no way to do an 8 bit out in one operation with the PORTD call? The documentation leads me to think you have to leave bits 0 and 1 alone for serial I/O and the other ports are 8 bits wide.

Thanks, -d

You can use ports D0 and D1 for digital operations, providing you haven’t turned on serial comms (with Serial.begin).

What timing / speed do you need? maybe shiftOut wit a 74HC595 can do the job too?

Thank you for those suggestions. I did plan on using the serial port and didn't want to resort to using a shift register but guess I will have to. Kind of irks me that the Arduino doesn't have 8 consecutive bits available for the user.

-d

Agree, now I think of it. Why not use PORTD as 8 bit parallel out and use newSoftSerial iso hardware Serial. It is quite reliable

How about a port-expander like the MCP23S17? That gives you 16 bits of general IO. It takes around 3 uS to send a byte via SPI and according to the MCP23S17 docs only 0.5 uS for the ports to change in response to valid data. That is still quite fast.

Or skip the intermediate chip and get an SPI DAC chip, like the MCP4921.

Or you could just use an arbitrary set of 8 pins as a virtual port:

uint8_t pins[8] = {2,3,4,5,6,7,8,9};
uint8_t dacVal;

[...]

void writeport() {
  for ( uint8_t i = 0; i < 8; i++ ) {
    digitalWrite( pins[i], dacVal & ( 1 << i ) );
  }
}