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

SPI help
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Dec 04, 2006 6:38 pm     Reply with quote

I checked the version number of the demo compiler on the website, currently this is v4.013d
Then I compared the generated list file of v3.249 with v4.013d for my posted example program. There are some differences but not something that causes me to think the demo compiler version is in error.

I'm not sure my demo program is correct as I don't have your chip for testing.
You say you are always reading zeroes, this is strange as it suggests the conversion is ready but the data always zero. Double check your hardware setup.
Make sure the SPI clock from PIC to the ADC is connected correctly.
Are you sure the ADC is not damaged?
What value do you expect to read?
What is connected to the Vref of the ADC?
It doesn't hurt to add a pull up on the dat line.
Check you read all ones when you temporarily tie the data line to Vcc.
etc.
das
Guest







SPI Help
PostPosted: Tue Dec 05, 2006 8:08 am     Reply with quote

I checked the version number of the demo compiler on the website, currently this is v4.013d
Then I compared the generated list file of v3.249 with v4.013d for my posted example program. There are some differences but not something that causes me to think the demo compiler version is in error.

I'm not sure my demo program is correct as I don't have your chip for testing.
You say you are always reading zeroes, this is strange as it suggests the conversion is ready but the data always zero. Double check your hardware setup.
Make sure the SPI clock from PIC to the ADC is connected correctly.
It Should be tied to Pin C3
Are you sure the ADC is not damaged?
I thought this might be the case too and replace the chip.
What value do you expect to read?
There is 4.95V coming in from a Dual Op-Amp
What is connected to the Vref of the ADC?
I set it for 5V.
It doesn't hurt to add a pull up on the dat line.
I will add this.
Check you read all ones when you temporarily tie the data line to Vcc.
That is a great idea... will do. Also, last night I was checking the Data Line and was not seeing my 1K ohm resistor. I am wondering if my re-work might have come loose.
das
Guest







SPI Help
PostPosted: Wed Dec 06, 2006 8:05 am     Reply with quote

I put a 1K pull up resistor on SDI (Pin C4). I checked and redid the rework on SDI. All the pins are connected correctly: SDI - PIN C4, SCK - PIN C3, CS - PIN D0. I am still just getting zeros. Is it possible that by toggling the pin it is putting the device to sleep? Is it necessary for me to add a:

#USE SPI()

designator?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Dec 07, 2006 3:59 am     Reply with quote

Quote:
Is it necessary for me to add a:

#USE SPI()

designator?
No, this is a new function in the v4 compiler. I haven't used it but the old functions are still working, my posted example program compiled without problems.

Receiving zeros is very strange, especially with the pull-up resistor on the data line present. With the MCP3551 in sleep mode or deselected the data line would go to high impedance, so you would read all 1's. If a conversion would still be going on you would also read ones.

You will have to figure out if it is the PIC or ADC that's causing the problems. Have you tried my suggested experiment for reading all ones?

I also have no clue as to what your schematic looks like. You gave some information but it is incomplete. Can you provide some kind of schematic? Even a handdrawn picture would suffice. You can send me private mail if you want to.
Ttelmah
Guest







PostPosted: Thu Dec 07, 2006 7:56 am     Reply with quote

This is 'trimmed' out of my code, since I am running a rather different processor etc..
Code:

union combine {
   int32 word;
   int8 b[4];
};
#byte PORTC=0x7
#bit SDI=PORTC.4
//will need a bit defintion here for CS

int32 read3551(void) {
   union combine temp;
   //drop CS
   CS=0;
   delay_cycles(1);
   CS=1;
   delay_cycles(1);
   //At this point conversion has been triggered.
   CS=0;
   delay_us(1);
   //wait for conversion to complete
   while (SDI==1) {
      CS=1;
      delay_cycles(1);
      CS=0;
   }
   //Now read data.
   temp.b[2]=spi_read(0);
   temp.b[1]=spi_read(0);
   temp.b[0]=spi_read(0);
   temp.b[3]=0;
   CS=1;
   return temp.word;
}     


Best Wishes
das
Guest







SPI Help
PostPosted: Wed Dec 13, 2006 8:26 am     Reply with quote

I cannot get the code to compile. I cannot get anything to work. I am not sure the next step to try to get this operating. I do not have the means to provide a schematic. It is connected like the datasheet with CS connected to PIN D0 on the PIC, SCKL to pin C3 on the PIC, and SDO connected to pin C4 on the PIC.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Dec 13, 2006 1:21 pm     Reply with quote

Quote:
I cannot get the code to compile. I cannot get anything to work.
You sound desperate...
I feel a bit sorry for you so here is a complete program:
Code:
#include <16F877A.h>
#fuses XT, NOWDT, NOLVP
#device *=16
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#use fast_io(c)
#use fast_io(d)


#define SPI_MODE_0_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_0_1 (SPI_L_TO_H)
#define SPI_MODE_1_0 (SPI_H_TO_L)
#define SPI_MODE_1_1 (SPI_H_TO_L | SPI_XMIT_L_TO_H)

#define LF  10
#define CR  13

union combine {
   int32 word;
   int8 b[4];
};

#byte PORTC=0x7
#bit SDI=PORTC.4
//will need a bit defintion here for CS
#byte PORTD=0x8
#bit CS=PORTD.0

int32 read3551(void)
{
   union combine temp;

   //drop CS
   CS=0;
   delay_cycles(1);
   CS=1;
   delay_cycles(1);
   //At this point conversion has been triggered.
   CS=0;
   delay_us(1);
   //wait for conversion to complete
   while (SDI==1) {
      CS=1;
      delay_cycles(1);
      CS=0;
   }
   //Now read data.
   temp.b[2]=spi_read(0);
   temp.b[1]=spi_read(0);
   temp.b[0]=spi_read(0);
   temp.b[3]=0;
   CS=1;
   return temp.word;
}     


void main()
{
  int8 i;
  int32 value;

  set_tris_c(0b10010000);   // C3 = CLK out, C4 = SDI, C6=XMIT, C7=RCV
  set_tris_d(0b00000000);   // D0 = CS

  CS=1;    //Start with CS high
  setup_spi(SPI_MASTER | SPI_MODE_1_1 | SPI_CLK_DIV_4 );

  puts("Initialized"); //Output string for debug
  while(TRUE)
 {
    value = read3551();

    for (i = 32; i>0; i--)
    {
      putc(bit_test(value, i-1) + '0');
    }
    putc(CR);
    putc(LF);

    delay_ms(5000);
  }
}


Quote:
I do not have the means to provide a schematic.
Sorry, but that's not enough. Use your imagination!
You must know someone with a scanner, digital camera or even a phone-camera so you can create a digital print of the schematic. Or use Microsoft paint, or whatever. Then post the digital picture on your own website or a free site like www.flickr.com and send us the link.

I'm especially interested in what and how everything is connected to the other 5 pins of the A/D converter (including pin numbers !)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
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