TX or MISO as GPIO while using serial as input only and SPI as output only?

Hello all,

This is my first post on this forum, though I have quite a bit of experience using electronics and other microcontrollers.

I attached my schematic to this post.
You can see that both TX and MISO are unused at the moment. I would like to use one of them as CS line for the second DAC, but have had no luck with my experimentation so far.

I attempted to make a hardware inverter but it seems that both of my DACs (MCP4822) are responding to all messages, even though I flip the CS line when appropriate.

channel_t is a type that can only be 1, 2, 3 or 4.
If the channel is larger than 2, send to second DAC (with inverted CS line) else send to first DAC.
The modulo calculation in the highByte declaration determines which output channel to select in the DAC.

void DACSPI(channel_t channel, unsigned int pitch){
  if (channel > 2){
    digitalWrite(8, LOW);
    digitalWrite(8, HIGH);
  }
  else {
    digitalWrite(8, HIGH);
    digitalWrite(8, LOW);
  }
  delay(1);
  byte lowByte = pitch & 0xFF;
  byte highByte = ((pitch >> 8) & 0xFF) | ((channel+1) % 2) << 7 | 0x10;
  SPI.transfer(highByte);
  SPI.transfer(lowByte);
  if (channel > 2){
    digitalWrite(8, LOW);
  }
  else {
    digitalWrite(8, HIGH);
  }
}

This code is starting to become a little cumbersome and I would prefer if I could use a second pin as GPIO.

Is it possible to use the unused TX or MISO pins as GPIO? I attempted this in a short test, but that did not seem to work. Maybe there is some workaround for that?

If this wouldn't work, maybe someone might be able to spot a problem in my code?

I'm not a transistor specialist but in my opinion the current limiting resistor on the base is missing in your circuit. Check if that damaged your Arduino pin and/or the transistor.

While using the hardware features UART and SPI their pins cannot be used otherwise at least if you use the IDE's libraries. The UART hardware can be used RX-only but the Serial object doesn't support that mode.

Thank you for your reply!
You are correct about the missing resistor, luckily I did put it on the breadboard!
Good to know that it is impossible with the normal libraries, I might try to find a solution for that, though I might just give up another pin.

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