![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
peter-storm
Joined: 26 Jan 2008 Posts: 11
|
SPI freezes PIC16f690 |
Posted: Tue Feb 26, 2008 6:33 pm |
|
|
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... |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 26, 2008 7:05 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
peter-storm
Joined: 26 Jan 2008 Posts: 11
|
|
Posted: Wed Feb 27, 2008 5:01 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 27, 2008 12:53 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|