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

PIC16F877 and MCP3909 help me!

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



Joined: 20 Jan 2011
Posts: 8

View user's profile Send private message

PIC16F877 and MCP3909 help me!
PostPosted: Thu Jan 20, 2011 2:28 am     Reply with quote

I try to connect MCP3909 with SPI function but it isn't work!

I link Avdd, Dvdd pin to +5V and AGND, DGND pin to 0V. Is it true?

And link G0,G1 to 0V.
Code:

#include "16f877.h"

#fuses    HS,NOWDT,PROTECT,NOLVP               
#use    delay(clock=10000000)
#use    rs232(baud=9600,xmit=PIN_A0,STREAM = LCD,INVERT)

#use SPI(DO = PIN_C2,DI = PIN_C3,CLK = PIN_C1,BITS = 8,MSB_FIRST,SAMPLE_RISE,stream = spiNa)

#define   CS   PIN_C0


void main(void)
{
   int a;
   int input=0;
   char i;
   
   set_tris_c(0b00001000);   //set port
   setup_spi(SPI_MASTER | SPI_H_TO_L); //set SPI mode
   
   output_low(CS);
   spi_xfer(spiNa,0b10100100); // write mode
   output_high(CS);
   
   while(1)
   {
      output_low(CS);
      if(spi_data_is_in())
      {
         input =spi_xfer(spiNa);
      }
      output_high(CS);
      
      
      fputc(0xFE,LCD);fputc(0x01,LCD);fprintf(LCD,"Earth");
      fputc(0xFE,LCD);fputc(0xC0,LCD);fprintf(LCD,"ch0: %d",input);
      delay_ms(600);
   }

}

Result on LCD is
Code:

 "Earth"
 "ch0: -1"

What wrong? Sad
Everybody help me, please... ><!
Jongnonkuk



Joined: 20 Jan 2011
Posts: 8

View user's profile Send private message

PostPosted: Fri Jan 21, 2011 1:59 am     Reply with quote

so sad -.-
Jongnonkuk



Joined: 20 Jan 2011
Posts: 8

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 1:46 am     Reply with quote

No one helps me. Sad

help me, please................................................
Jongnonkuk



Joined: 20 Jan 2011
Posts: 8

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 1:47 am     Reply with quote

Code new: (not work again -.-)
Code:

#include "16f877.h"

#fuses  HS,NOWDT,PROTECT,NOLVP               
#use    delay(clock=10000000)
#use    rs232(baud=9600,xmit=PIN_A0,STREAM = LCD,INVERT)

#define   CS   PIN_C0
#define   SCK   PIN_C1
#define   SDO   PIN_C2
#define   SDI   PIN_C3
#define   MCLR        PIN_C4


void clockdata(unsigned char bits_in);
void writedata(unsigned char data_in);


void main(void)
{
   
   char TextBuff[16];
   int16 In;
   int16 ch0=0,ch1=0;
   char i,x=1;
   
   set_tris_c(0b00001000);   //set port
   
   output_bit(CS,1);   // Disable chip select
   output_bit(MCLR,1);   
   
   writedata(0b10101100);
   
   

   while(1)
   {

      output_bit(CS,0);   // Active chip select
      In = 0;
      output_bit(SCK,1);   // make clock high first
      
      for(i=1;i<=16;i++)
      {
         output_bit(SCK,0);
         
         In <<=1;
         In = In | (input(SDI) & 0x01);
         
         output_bit(SCK,1);
      
      }
      ch0 = In;
      
      In = 0;
      for(i=1;i<=16;i++)
      {
         output_bit(SCK,0);
         
         In<<=1;
         In = In | (input(SDI) & 0x01);
         
         output_bit(SCK,1);
      
      }
      ch1 = In;
      output_bit(CS,1);   // Disable chip select
      
      
      
      fputc(0xFE,LCD);fputc(0x01,LCD);fprintf(LCD,"Earth");
      fputc(0xFE,LCD);fputc(0xC0,LCD);fprintf(LCD,"ch0: %Ld",ch0);
      fputc(0xFE,LCD);fputc(0x94,LCD);fprintf(LCD,"ch1: %Ld",ch1);
   
      delay_ms(1000);
      
   }//while(1) ...end



}


void writedata(unsigned char data_in)
{
   output_bit(MCLR,0);   //chip Reset
   delay_us(2);
   output_bit(MCLR,1);
   delay_us(1);
   
   output_bit(CS,0);   // Active chip select
   output_bit(SCK,0);   // make clock low first
   
   clockdata(data_in);   // Clock in data bits.
   output_bit(CS,1);   // Disable chip select
}

void clockdata(unsigned char bits_in)
{
   int bitcnt;
   for (bitcnt=8; bitcnt>0; bitcnt--)
      {
         output_bit(SCK,1);   // clock                        // Set Clock Idle level LOW.
         if ((bits_in&0x80)==0x80) {output_bit(SDO,1);}      // PCD8544 clocks in the MSb first.
         else {output_bit(SDO,0);}
         output_bit(SCK,0);   // clock                        // Data is clocked on the rising edge of SCK.
         bits_in=bits_in<<1;                  // Logical shift data by 1 bit left.
      }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 3:07 pm     Reply with quote

The reason that no one gives you a reply, is because this is a complicated
chip and no one wants to write the driver for you. I've looked at it two
times recently, and I don't have the time to write the driver for you.
Jongnonkuk



Joined: 20 Jan 2011
Posts: 8

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 7:53 pm     Reply with quote

good answer. Evil or Very Mad

thank.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 9:38 pm     Reply with quote

I've seen worse (harder) chips to get 'online'. Everything you need is in the data sheet, looks like SPI mode 1 for communications.

Writing a driver isn't that much of a challenge but too bad it's not available in a DIP package, far easier for my old eyes to breadboard and tinker with !

Sure looks like board layout would be 'fun', maybe Microchip has a 'test board' available ? If not, wait a week or two, someone will once they see the potential for the chip.
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