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