Go Down

Topic: Im having trouble communicating to a PGA2310 chip (Read 3774 times) previous topic - next topic

Stian

Hi all!

Im working on a volume controller, based on Texas Instrument`s PGA2310 Digital volume-controller chip, but im having some trouble making it work at all.
Here is how my code looks:
Quote

#include "SPI.h"

const int PGA_CS_PIN = 48;
const int PGA_SCLK_PIN = 52;
const int PGA_SDI_PIN = 51;

int timedelay = 100;
int volumeLevel = 55;

void setup() {
pinMode(PGA_CS_PIN,OUTPUT);
pinMode(PGA_SCLK_PIN,OUTPUT);
pinMode(PGA_SDI_PIN,OUTPUT);
digitalWrite(PGA_CS_PIN,HIGH);
digitalWrite(PGA_SCLK_PIN,HIGH);
digitalWrite(PGA_SDI_PIN,HIGH);
Serial.begin(9600);
}

void PGA_set_volume(byte value)
{
 byte shifted_val = (value << 1);   
digitalWrite(PGA_CS_PIN, LOW); // assert CS
SPI_write(shifted_val); // right value (0..255)
SPI_write(shifted_val); // right value (0..255)
digitalWrite(PGA_CS_PIN, HIGH); // deassert CS
Serial.print(shifted_val);
}

static inline void SPI_write(byte out_spi_byte)
{
byte i;
// loop thru each of the 8-bits in the byte
 for (i=0; i < 8; i++) {
// strobe clock
digitalWrite(PGA_SCLK_PIN, LOW);
// send the bit (we look at the high order bit and 'print' that to the remtoe device)
if (0x80 & out_spi_byte) // MSB is set
digitalWrite(PGA_SDI_PIN, HIGH);
else
digitalWrite(PGA_SDI_PIN, LOW);
// unstrobe the clock
digitalWrite(PGA_SCLK_PIN, HIGH);
out_spi_byte <<= 1; // left-shift the byte by 1 bit
}
}

void loop()
{
// Reset the volumeLevel if it goes over 128. I think it can actually go to 255.
//if (volumeLevel > 254) {
//volumeLevel = 1;
//}
// Set the volume
PGA_set_volume(volumeLevel);
delay(timedelay);
volumeLevel = volumeLevel + 1;
}


And using the serial communication too see what the arduino says to the chip, this is what comes:
Quote
 "$&(*,.02468:<>@BDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~???????


I have no idea why this happens, Ive just started with arduino so im basically an extremely newbie... :o

Some of this code comes from what linux-works once posted, basically its the only thing i can find, except linux-works PGA23XX library witch i dont now how works.

Can some one help sort this out?

Thanks,
Stian

Stian

Maybe this post belongs under "Programming Questions", could a moderator move it for me if so?

Stian

Found a new code for it: http://code.google.com/p/dccn-lab/source/browse/trunk/audiovolume/Arduino/pga2311_volume_control/pga2311_volume_control.pde?r=59
This one seems to be working good.

I also breadboarded the project a little more professional, should SDI, CLK, CS, ZCEN, MUTE have pulldown and pullup resistors?
Atleast, now i am using:
SDI: 100k pulldown
CLK: 100k pullup
CS: 100k pulldown
ZCEN: 47k pulldown
MUTE: 47k pulldown

Grumpy_Mike

Quote
should SDI, CLK, CS, ZCEN, MUTE have pulldown and pullup resistors?

Simply no.

You only need pull up resistors on open collector inputs, and pull down when you don't want pins to float during initialisation.


opet

Hi,

I'm currently trying to do the same thing, replacing a normal volume pot with a digital arduino based solution. I haven't seen any schematics of how anyone have connected the actual amp to the PGA2310 and I was wondering if it requires any additional hardware. Or do I just connect the lines and that's it?

Thanks in advance!

√ėyvind

Go Up