Pages: [1]   Go Down
Author Topic: Port Manipulation problem  (Read 1522 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there!
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!
//  digitalWrite(ADSS3,LOW);
  MSB3 = SPI.transfer(0);
  LSB3 = SPI.transfer(0);
//  digitalWrite(ADSS3,HIGH);
  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

Offline Offline
Edison Member
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I don't see it.
I only noticed that this one "B0111111" is only 7 bits.

You could create a test sketch. Make the pin low, wait 2 seconds, make it high, wait, and so on.
Start with the led on pin 13 (PORTB5).

Online Online
Shannon Member
Karma: 222
Posts: 12714
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Humans find binary constants hard to read, hexadecimal notation is easier once you are used to it IMO,
since it groups in sets of 4 bits its harder to slip up by one bit (you can slip up by 4 bits though, but only
with long values in practice).  Its also far far easier to memorize a hex number, even temporarily.

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: