ATMega644p with serial digital pot

I am using the mcp4251 digital potentiometer and have it working perfectly with the atmega328p on the bare bones board, I try to port it over to the atmega644p and have no luck getting it to work. I am using the code from http://www.arduino.cc/en/Tutorial/SPIDigitalPot to get it to work on the 328. I did have to change the channel info to get it to work with both wipers since it requires a different bit set. That can't be the issue since the chip is expecting them to be those bits. I tried using #10, #9, and even the actual SS pin which I assume is 12. Set all the pins to output, hooked up the sck and the mosi pins and nothing seems to work. any ideas? could my spi.h file be messed up. it does have it commented in the file "// PB4(MISO), PB3(MOSI), PB5(SCK), PB2(/SS) " which is not right on the 644.

No replies, huh?

Post your code. Post your error messages. Post your wiring.

... have no luck getting it to work.

What sort of bad luck are you having? Compiler errors? It doesn't actually do anything?

I tried using #10, #9, and even the actual SS pin which I assume is 12.

Why assume? What pin is it? According to the Atmega644 spec it is pin 5 on the processor (on a PDIP package). What board are you using that you think it is pin 12?

I am using this code:

// inslude the SPI library:
#include <SPI.h>


// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;  //tried digital 12 also

void setup() {
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin(); 
}

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 0; channel < 2; channel++) { 
    // change the resistance on this channel from min to max:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, level);
      delay(10);
    }
    // wait a second at the top:
    delay(100);
    // change the resistance on this channel from max to min:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, 255 - level);
      delay(10);
    }
  }

}

int digitalPotWrite(int address, int value) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin,LOW);
  //  send in the address and value via SPI:
  SPI.transfer(B00010010);
  SPI.transfer(value);
  SPI.transfer(B00000010);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH); 
}

The B00010010 is the address info for the MCP4251 that I know works since I can get it to work with the atmega328p (bare bones board).

I am not actually getting any error messages, The LEDs I have hooked up to the digital pot just stay at the mid point.
I started programming with the pic first. I liked being able to just do something like portB.6 HIGH, but that doesn’t work with arduino.
and you’re right it is pin 5 on the dip I am using, but that means it’s digital pin 12. MOSI is digital 13 so far both of those lign up with the pcint numbers on the datasheet, but digital 14 and 15 are actually being used as #22 (PC0) and #23 (PC1) and I that’s leading me to believe that the hardware is not setup right in my folders.
here is the hardware:
boards.txt

##############################################################

sanguino.name=Sanguino
sanguino.upload.protocol=stk500
sanguino.upload.maximum_size=63488
sanguino.upload.speed=38400
sanguino.bootloader.low_fuses=0xFF
sanguino.bootloader.high_fuses=0xDC
sanguino.bootloader.extended_fuses=0xFD
sanguino.bootloader.path=atmega644p
sanguino.bootloader.file=ATmegaBOOT_644P.hex
sanguino.bootloader.unlock_bits=0x3F
sanguino.bootloader.lock_bits=0x0F
sanguino.build.mcu=atmega644p
sanguino.build.f_cpu=16000000L
sanguino.build.core=arduino

Here’s my board attached
Assume all the usb and power requirements are done on the 644p fritzing didn’t have a sanguino option or arduino with a 40 pin chip.

ad5206_bb.jpg

The pins used in the SPI library are not the pins the 644 uses for it's SPI hardware, so I suspect that is your problem.

Have you tried bit banging the SPI pins?

Can you post a schematic because Fritzing pretty pictures are absolute rubbish for seeing if a circuit is correctly designed.

redteardrop: I am not actually getting any error messages, The LEDs I have hooked up to the digital pot just stay at the mid point. I started programming with the pic first. I liked being able to just do something like portB.6 HIGH, but that doesn't work with arduino. and you're right it is pin 5 on the dip I am using, but that means it's digital pin 12.

According to my pins_arduino.h file for my Sanguino:

// SPI pin numbers
//
#define SS    4   // PB4
#define MOSI  5   // PB5
#define MISO  6   // PB6
#define SCK   7   // PB7

Interesting, I thought that my problem would be in the pin defenitions for the 644 since it was capping the ports to the same number of outputs that the 328 have (i.e. no B7, B6 or B5)
I checked my pins_arduino.h file in the cores folder for my sanguino and it doesn’t show any of that. I checked the .c file too. I opened the file directly from the Sanguino-0018r2_1_4 zip file too just to make sure I didn’t overwrite the file by mistake.
Maybe I’m missing the right download. I got it directly from the sanguino website and I’m using arduino 22 so it auto updates the folder and file location from what I can tell (no longer needing to put files in a library folder).
I think the 644 defenitions might have been lost somewhere, I never messed with the folders or files though except adding the sanguino stuff. I see the definitions in the io.h file in the avr directory.
Just checking and the pins file has the #include for the avr/io.h which points to the 644 definitions…
I dunno I am getting confused. I’ll try arduino-18 from scratch and see if I can get that to work on fresh install.
I am attaching my schematic too.
I have no experience w/ bitbang so I can’t give any info on that.

Your circuit appears to indicate that pins 5, 6, 7, 8 are the relevant ones. They are brought out to 5, 6, 7, 8 on JP1.

However since internally pins start at 0, (ie. PB0, PB1 …) then you want PB4, PB5, PB6, PB7.

Provided you have connected them correctly to your other device you don’t need to “tell” SPI which ones to use, the hardware does that. Just make sure you get SS right (test with a meter if you have to).