PGA117 driver

April 9, 2013 Coded in C for the TI MSP430

This is a driver to interface PGA117 with MSP430(compiled in Code composer studio)

#define READ 0x6A00
#define WRITE 0x2A00
#define NOP WRITE 0x0000
#define SDN_DIS 0xE100
#define SDN_EN 0xE1F1

#define GAIN_1		0
#define GAIN_2		1
#define GAIN_4		2
#define GAIN_8		3
#define GAIN_16		4
#define GAIN_32		5
#define GAIN_64		6
#define GAIN_128	7

#define CS BIT0
#define DI BIT1
#define DO BIT2

void write_pga(unsigned int value);
void set_ch_gain(unsigned int ch,unsigned int gain);
void config_spi();

void config_spi()
	P1DIR |= 0x01;                            // P1.0 output
	P3SEL |= 0x0C;                            // P3.2,3 USCI_B0 option select
	P3DIR |= 0x01;                            // P3.0 output direction
	UCB0CTL0 |= UCMSB + UCMST + UCSYNC;       // 3-pin, 8-bit SPI mstr, MSB 1st
	UCB0CTL1 |= UCSSEL_2;                     // SMCLK
	UCB0BR0 = 0x02;
	UCB0BR1 = 0;
	UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

void write_spi(char data)
	UCB0TXBUF = data;                  // Byte to SPI TXBUF
	while (!(IFG2 & UCB0TXIFG));       // USCI_A0 TX buffer ready?

void write_pga(unsigned int value)
	P3OUT &= ~CS;
	P3OUT |= CS;

void set_ch_gain(unsigned int ch,unsigned int gain)
	unsigned int command;
	command = gain<<4;
	command += ch;
	command +=WRITE;



There are no comments yet!

Sorry, you need javascript enabled to post any comments.