=A0 Hello All I am trying to interface a 16F877 to MCP3202(12 bit ADC with SPI interf= ace). I am not able to get data from the MCP3202(ALL I GET IS ZERO. I am using the standard SPI module of 16F877A, connected to the SPI pins of= MCP3202 as required. I tried pulling up as well as pulling down the CS,Clk,SDI,SDO pins with= out any results. I used a DSO and saw that the wave forms of the CS,CLK,SDO of the 16F87= 7A are as required. CS goes low. then the data transmission on clk fro 16F877 are just as r= equired. Still i do not get the ADC values. what could be wrong.where could i ha= ve gone wrong. Is there anything else i have to consider. Please find the code i used below for hi-tech c compiler ////start of code for MCP3202<-->16F877A #include #define ADCS 0x04 /* I/O bit position for CS line */ #define BUSY 0x01 /* Bit0 of SSPSTAT, indicated when SPI xmission complete = */ #define BUTTON 0x10 /* I/0 bit position for RA4 line */ void Wait_for_Press() { while(PORTA & BUTTON) { /* wait for button press */ } while(!(PORTA & BUTTON)) { /* wait for button release */ } } unsigned char datah,datal; int del; void main(void) { PORTA=3D0; PORTB=3D0; PORTC=3D0; PORTD=3D0; PORTE=3D0; = TRISA =3D 0x00; = TRISD =3D 0x00; TRISE =3D 0x00; TRISB =3D 0x00; PORTB =3D 0x00; /* reset PortB outputs */ SSPCON =3D 0x32; /* set up SSP to clock data out on falling edge */ TRISC =3D 0x90; /* clock data in on rising edge, clock idle high */ PORTC |=3D ADCS; /* de-select A/D device */ ////////////UART/////////////////////////// TXSTA=3D0x84; RCSTA=3D0x90; = = TXEN=3D1; = TMR1IE=3D0; = //OPTION=3D0X97; = SPBRG=3D0X19; = T0IF=3D0; T0IE=3D0; PEIE=3D1; RCIE=3D0; CREN=3D1; SPEN=3D1; SYNC=3D0; TXEN=3D1; datal=3D0xAA; datah=3D0xBB; while(TRMT!=3D1); TXREG=3D66; /////////////////////////////////////////// while(1) { PORTC &=3D ~ADCS; /* select A/D device */ //RC2=3D1; SSPBUF =3D 0x00; /* output start bit */ while(!(SSPSTAT & BUSY)) { /* wait for transfer complete */ } SSPBUF =3D 0x01; /* output start bit */ while(!(SSPSTAT & BUSY)) { /* wait for transfer complete */ } datah =3D SSPBUF; /* mask and output conversion MSb=92s */ SSPBUF =3D 0xa0; /* output 3 command, 5 dummy bits */ while(!(SSPSTAT & BUSY)) { /* wait for transfer complete */ } datah =3D SSPBUF;// & 0x0F; /* mask and output conversion MSb=92s */ SSPBUF =3D 0x00; /* output dummy word */ while(!(SSPSTAT & BUSY)) { /* wait for transfer complete */ } datal=3DSSPBUF; PORTC |=3D ADCS; /* de-select A/D device */ //RC2=3D0; TXEN=3D1; while(TRMT!=3D1); TXREG=3Ddatah; while(TRMT!=3D1); TXREG=3Ddatal; for(del=3D32000;del>0;del--) { # asm nop nop nop nop nop nop # endasm } } } = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist