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 freezes PIC16f690

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



Joined: 26 Jan 2008
Posts: 11

View user's profile Send private message

SPI freezes PIC16f690
PostPosted: Tue Feb 26, 2008 6:33 pm     Reply with quote

Hi all,

If I implement my code using spi_write() the program works. If I use spi_xfer instead, it hangs at the first instance of this command and I'm not sure why. The help doesn't really explain the difference between spi_write() and spi_xfer(), but it appears that spi_xfer() uses much less memory.

Here is a segment of my code, any help is appreciated.

Code:

#fuses HS, NOWDT, NOPROTECT, BROWNOUT
#use delay(clock=8000000)
#use rs232(baud=19200,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8,STREAM=ETRX)
#use spi(FORCE_HW,SPI1,MASTER, BITS=8, LSB_FIRST,ENABLE=PIN_C6)
#include <string.h>
#include <vl1001.c>
#include <ascii-bitmapping.c>

here is the function where it crashes:


void upd_lcd()
{
char time1[18];
char time2[18];
char activity1[18];
char activity2[18];


gets(time1);
gets(activity1);
gets(time2);
gets(activity2);

spi_xfer(0xa3); << this is where it stops working
spi_xfer(0x1a);
etc...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 26, 2008 7:05 pm     Reply with quote

1. Make it into a complete test program. Only put lines of code in
the program that are needed to show the problem. For example,
if you can demonstrate the problem without all those #include files
and without all the gets() statements, then delete them.

See my post in this thread, where I show some test programs:
http://www.ccsinfo.com/forum/viewtopic.php?t=33372
This is what I mean. If you can strip your code down to a program
as short as that, then I can probably find the problem.


2. Very important: Post your compiler version.
peter-storm



Joined: 26 Jan 2008
Posts: 11

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 5:01 am     Reply with quote

Code:

#include <16f690.h>

#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=8000000)
#use rs232(baud=19200,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8,STREAM=ETRX)
#use spi(FORCE_HW,SPI1,MASTER, BITS=8, LSB_FIRST,ENABLE=PIN_C6)


void main()
{
   set_tris_c (0x00);
   setup_adc_ports (NO_ANALOGS | VSS_VDD);
   setup_adc (ADC_OFF);
   setup_spi (SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
   setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_1);
   
   setup_timer_1 (T1_DISABLED);
   setup_timer_2 (T2_DISABLED, 0, 1);
   setup_comparator (NC_NC_NC_NC);
   setup_oscillator (OSC_8MHZ);

   

   
     
 

  printf("AT+SCAST:UPD\r");
   
   delay_ms(2000);
   spi_xfer(01010101);
   
   printf("AT+SCAST:BAT\r");
   
 
 

}


My compiler version is 4.057.

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 12:53 pm     Reply with quote

Quote:
#include <16f690.h>

#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=8000000)
#use rs232(baud=19200,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8,STREAM=ETRX)
#use spi(FORCE_HW,SPI1,MASTER, BITS=8, LSB_FIRST,ENABLE=PIN_C6)

void main()
{
set_tris_c (0x00);
setup_adc_ports (NO_ANALOGS | VSS_VDD);
setup_adc (ADC_OFF);
setup_spi (SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_1);

setup_timer_1 (T1_DISABLED);
setup_timer_2 (T2_DISABLED, 0, 1);
setup_comparator (NC_NC_NC_NC);
setup_oscillator (OSC_8MHZ);

printf("AT+SCAST:UPD\r");

delay_ms(2000);
spi_xfer(01010101);

printf("AT+SCAST:BAT\r");

}


CCS has two methods of using SPI. The original method uses
setup_spi() to configure the SPI module, and spi_write(), spi_read(),
etc., to do the SPI transfers.

The new method does the SPI setup with a #use spi() statement,
and it does the transfers with spi_xfer().

You should not mix these two methods. In your code above, you're
using the new method, so you should delete the setup_spi() statement.
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