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 CCS Technical Support

MCP3021 don't work!

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 01, 2007 2:46 pm     Reply with quote

Try a more simple program:
Code:
#include <16F628A.H>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#use i2c(master, scl=PIN_A2, sda=PIN_A3)

#include <flex_lcd.c>

//-----------------------------------
#define MCP3021_READ_ADDR 0b10011011

int16 read_mcp3021(void)
{
int8 lsb;
int8 msb;
int16 retval;

i2c_start();
i2c_write(MCP3021_READ_ADDR);   
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();

retval = make16(msb, lsb) >> 2;

return(retval);
}


//============================
void main()
{
int16 result;

lcd_init();

while(1)
  {
   result = read_mcp3021();
   printf(lcd_putc, "\f%lx    ", result);
   delay_ms(500);
  }
}
Doglao



Joined: 26 Mar 2007
Posts: 11

View user's profile Send private message MSN Messenger

PostPosted: Thu Nov 01, 2007 4:06 pm     Reply with quote

Thanks for all!
it is working now!
I put a 11us delay before read the data, this delay is necessary to make a acquisition time Tacq(1.12usec) plus Conversion Time Tconv(8.96) and this work well, the values changing linearity. the other thing that I know now, is to join msb and lsb with make16() command.
very very very thanks!!
_________________
Breaking rocks in the hot sun!
Doglao
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