|
|
View previous topic :: View next topic |
Author |
Message |
Jongnonkuk
Joined: 20 Jan 2011 Posts: 8
|
PIC16F877 and MCP3909 help me! |
Posted: Thu Jan 20, 2011 2:28 am |
|
|
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
What wrong?
Everybody help me, please... ><! |
|
|
Jongnonkuk
Joined: 20 Jan 2011 Posts: 8
|
|
Posted: Fri Jan 21, 2011 1:59 am |
|
|
so sad -.- |
|
|
Jongnonkuk
Joined: 20 Jan 2011 Posts: 8
|
|
Posted: Tue Jan 25, 2011 1:46 am |
|
|
No one helps me.
help me, please................................................ |
|
|
Jongnonkuk
Joined: 20 Jan 2011 Posts: 8
|
|
Posted: Tue Jan 25, 2011 1:47 am |
|
|
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
|
|
Posted: Tue Jan 25, 2011 3:07 pm |
|
|
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
|
|
Posted: Tue Jan 25, 2011 7:53 pm |
|
|
good answer.
thank. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Jan 25, 2011 9:38 pm |
|
|
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. |
|
|
|
|
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
|