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?
