I'm expanding on my project from last year and changing pins etc etc
However, I've run into a problem with my port manipulations.
I have ADC 1 on pin6, ADC2 on 7, and ADC #3 on pin 8, with which I'm communicating over SPI. So what I need to do is flick the AD1 pin low to start the communication, then transfer 2 bytes, then bring it high again, then move onto the next chip.
My program works fine if I switch out the port manipulations for digitalWrite(AD#,LOW); digitalWrite(AD#,HIGH), and strangely also the pin 8 port manipulation works.
Can someone point out the error? Here's the code:
//PORTD &= B10111111; //THIS isn't working...
MSB1 = SPI.transfer(0);
LSB1 = SPI.transfer(0);
PORTD |= B01000000; //Neither is this
valAD1 = ((MSB1 & TMP) << 6) | (LSB1 >> 2);
// PORTD &= B0111111; // pull SS of second ADC (pin 7) LOW (ADC sample)
MSB2 = SPI.transfer(0);
LSB2 = SPI.transfer(0);
// PORTD |= B10000000; // pull pin 7 of arduino to HIGH (ADC off) = PORT MANIPULATION
valAD2 = ((MSB2 & TMP) << 6) | (LSB2 >> 2);
PORTB &= B11111110; // pull SS (pin 8) LOW (ADC sample) <-------- this block of code works!
MSB3 = SPI.transfer(0);
LSB3 = SPI.transfer(0);
PORTB |= B00000001; // pull SS (pin 9) of arduino HIGH (ADC off)
valAD3 = ((MSB3 & TMP) << 6) | (LSB3 >> 2);
I'd like to know what I'm doing wrong with my pin 6 and 7 port manipulations. I need the extra speed for my project.
Arduino Uno r3