View previous topic :: View next topic |
Author |
Message |
BeaTk Guest
|
help! spi ADC using PIC |
Posted: Thu Feb 23, 2006 7:20 am |
|
|
I try to connect MCP3001 connect with PIC16f88 but I can't write the program to get the value from the ADC. Could anyone help me with the coding
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOCPD,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
int x = 0;
void main()
{
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
while(1);
{
spi_write(0x3c);
if(spi_data_is_in())
{
x=spi_read();
delay_ms(11);
}
delay_ms(11);
}
}
I try to use this code but I dont know how to get value from the ADC |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Thu Feb 23, 2006 12:11 pm |
|
|
You didnt use a CS pin.
Your chip isn't listening because its not selected..... CHIP SELECTED...
Tie an output to the CS pin, output_low before a command and output_high after. |
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Thu Feb 23, 2006 12:23 pm |
|
|
Plus, the code you chose has some syntax problems. Read further in the thread you got it from to see some of the advice given to its author _________________ The difference between genius and stupidity is that genius has its limits... |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Thu Feb 23, 2006 1:39 pm |
|
|
Also, you may have to look into MODE 00 or 11 for SPI... there are posts about this, one from DougH I think.
Oh, your pic may have to supply the clock to the MCP... so try a
That will send a 0 which the ADC will probably ignore, but it will make the clock line pulse giving the ADC an oppertunity to send its data to you. Kinda.
And... You never check 'x' |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 23, 2006 2:56 pm |
|
|
Quote: | I try to connect MCP3001 connect with PIC16f88 but I can't write the program to get the value from the ADC. |
That code is junk code. It's not a driver. Don't use it. |
|
|
|