Pga2311 pic16f877 spi interface code

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Though I don't know much about PICs (my favourites are Atmel's µCs), there's a piece of advice I can give:
have a look into the PGA's datasheet at section "serial control port".
Everything you need is in there :) I did the same when building my preamp and it was done in less than 1 hour.
Good luck!

 
anyone help?
with this code I can't control the pga2311.


#include <16f877A.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD

#use delay(clock=4000000)

#use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, stop=1)
#use spi (master, DI=pin_C2, DO=pin_C1, CLK=pin_C0 ,SAMPLE_RISE,bits=16,LSB_FIRST,IDLE=0)

#define CS PIN_C3 // CS ifadesi PIN_C2 pini yerine atanıyor

int16 N;
void main ()
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);



output_high(cs);
N=0;
while(1)
{ output_low(cs);
if (input(pin_A5))
{N=N+1;
output_low(cs);
delay_ms(20);
spi_xfer(N);
output_high(cs);
delay_ms(50);

}
}
}
 
kualrea said:
with this code I can't control the pga2311.
Obviously it isn't :D Where did you get that sourcecode? It looks a bit weird to communicate with a PGA2311.
Did you scope the bus already?
I suggest to build up your control word like that:
One Byte (let's call it "left") contains the volume for the left channel.
Another one (call it "right") represents the volume of the right channel.
Now you take a 16-bit variable (let's call it "volume") and do the following:
[pseudo code] volume = right*256 + left [/pseudo code]
Now you can transmit THIS variable via SPI to your PGA2311.

I hope, this short post will help you a bit :)
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.