HI all
I am using ADS7844E with pic microcontroller in our application i am writing 0x97 correctly to ADC but i m unable to receive data please help. please find my code below.
please find the waveform writing to adc
void InitSPI()
{
SPI2CON1bits.DISSCK = 0; //Internal Serial Clock is Enabled.
SPI2CON1bits.DISSDO = 0; //SDOx pin is controlled by the module.
SPI2CON1bits.MODE16 = 1; //Communication is byte-wide (8 bits).
SPI2CON1bits.SMP=0; //Input Data is sampled at middle of data output time.
//Serial output data changes on transition from idle clock state to active clock state
SPI2CON1bits.CKE = 0;
//Idle state for clock is a low level; active state is a high level
SPI2CON1bits.CKP = 1;
SPI2CON1bits.SSEN=0; //SSx Pin not used by the module
SPI2CON1bits.MSTEN = 1; //Master Mode enabled
SPI2CON1bits.SPRE=0b001; //Secondary prescalar is 4:1 //FCY is 20MHz
SPI2CON1bits.PPRE=0b11; //Primary prescalar is 1:1
SPI2CON2bits.FRMEN=0; //Framed SPI support is disabled
SPI2STATbits.SPIEN=1; //Enable SPI Module
SPI2STATbits.SPISIDL=0; //Continue Module operation in idle mode
SPI2STATbits.SPIROV=0; //Receive overflow flag is cleared
}
unsigned int SPI_Recieve(void)
{
SPI2STATbits.SPIRBF=0;
SPI2BUF=0x00;
while(!SPI2STATbits.SPIRBF);
return SPI2BUF;
}
void SPI_Send(unsigned char Data)
{
SPI2BUF=Data;
while(SPI2STATbits.SPITBF);
while(!SPI2STATbits.SPIRBF);
Data=SPI2BUF;
}
main()
{
while(1){
unsigned int Read_ExternalADC(char channel) {
char ControlByte, Start;
int Data;
//ch 0 = current. ch 1 = feedback. ch 2 = voltage
Start = 0x87;
ExternalADC_CS = 0;
ControlByte = Start | (channel << 4);
SPI_Send(ControlByte);
// Delayus(500);
Data = SPI_Recieve();
ExternalADC_CS = 1;
return (Data & 0x0FFF);
}
}
}