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

Problem with SPI - PIC16F687

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



Joined: 31 Jan 2005
Posts: 3

View user's profile Send private message MSN Messenger ICQ Number

Problem with SPI - PIC16F687
PostPosted: Wed Aug 16, 2006 6:41 am     Reply with quote

When I try to write a byte on SPI, the program crashes.
Here is my code:
Code:

#include "16F687.h"

#fuses XT, NOWDT, PUT, NOMCLR, NOBROWNOUT, NOCPD, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=3686400)

#byte PORTA  = 0x05
#byte PORTB  = 0x06
#byte PORTC  = 0x07
#byte TRISA  = 0x85
#byte TRISB  = 0x86
#byte TRISC  = 0x87
#bit TEST    = PORTC.0

void main()
{
   TRISA = 0x08;
   TRISB = 0x30;
   TRISC = 0x00;

   setup_comparator(NC_NC_NC_NC);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);

   PORTA = 0x00;
   PORTB = 0x00;
   PORTC = 0x00;

   while(true)
   {
      TEST = 1;
      spi_write(0x55);
      delay_us(50);
      TEST = 0;
   }
}
ckielstra



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

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 7:39 am     Reply with quote

What is your compiler version?

How do you know your program crashes? You have no delay between setting TEST 0 to 1, so the output will be low for only a few clock cycles.
vinims



Joined: 31 Jan 2005
Posts: 3

View user's profile Send private message MSN Messenger ICQ Number

PostPosted: Wed Aug 16, 2006 8:22 am     Reply with quote

ckielstra wrote:
What is your compiler version?

3.249

ckielstra wrote:

How do you know your program crashes? You have no delay between setting TEST 0 to 1, so the output will be low for only a few clock cycles.

After spi_write(0x55) code line I was trying to send a byte through rs232 and I did not get any answer from PIC.
But if I comment spi_write(0x55) code line, it works perfectly.
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