CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

help! spi ADC using PIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
BeaTk
Guest







help! spi ADC using PIC
PostPosted: Thu Feb 23, 2006 7:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Feb 23, 2006 12:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Feb 23, 2006 12:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Feb 23, 2006 1:39 pm     Reply with quote

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
Code:

x=spi_read(0);   

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

View user's profile Send private message

PostPosted: Thu Feb 23, 2006 2:56 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group