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

16F88 restarts on incoming RS232 data

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







16F88 restarts on incoming RS232 data
PostPosted: Sun Feb 11, 2007 9:57 am     Reply with quote

Hello everybody,

my big problem is that everytime I send some data by the rs232 from my computer to the 16F88 he restarts. Any idea what could be the problem?

I find out if the PIC restart 'cause I light up for 500ms a green LED. Is the interrupt called a red LED schould light up, but nothing happend because the PIC restarts befor.

Code:
// Config
#include <16F88.h>


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES PUT                      //Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOBROWNOUT                 //No reset when brownout detected
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled

#use delay(clock=8000000)

// Using hardware-USART
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)



// Interrupt for incoming rs232 data
#int_RDA
RDA_isr()
{
output_high(PIN_A6);   // red-LED to give my a sign interrupt called
putc(getc()+2);   // return me a sign on Hyperterminal
}

void main() {

// Init
port_b_pullups(TRUE);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC);

// Give ma a sign that PIC restarts
output_high(PIN_A0);   // green-LED
delay_ms(500);
output_low(PIN_A0);

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);


while (1) {
// give ma a sign that PIC is working and successfully programmed
output_low(PIN_A1);
delay_ms(500);
output_high(PIN_A1);
delay_ms(500);
output_low(PIN_A6);

}
}


I'm slowly going to be crazy because I'm searching for the error for over 1 week now with no success.

I hope somebody has any idea that can fix this problem.

Thank you!
Benny
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 3:05 pm     Reply with quote

I tested your program with PCM vs. 3.249, and I couldn't duplicate your
problem. The program never re-started. It fact, it didn't work with
regard to the RS-232 at all.

The reason is because of the "setup_spi(FALSE)" statement. In the
16F88, the Rx and the SDO pins are both on Pin B2. When you put
in the setup_spi(FALSE), the compiler generates this ASM code:
Quote:

......... setup_spi(FALSE);
0077: BCF 14.5
0078: BSF 03.5 // Bank 1
0079: BCF 06.2 // TRISB.2 = output
007A: BSF 06.1 // TRISB.1 = input
007B: BCF 06.4 // TRISB.4 = output
007C: MOVLW 00
007D: BCF 03.5
007E: MOVWF 14
007F: BSF 03.5
0080: MOVWF 14

It's setting the Rx pin as an output. This prevents the UART from
receiving characters from your PC. The program can't work, until
you delete the setup_spi(FALSE) statement. The SPI module is
disabled on power-on reset anyway. You don't need that line of code.
shooter
Guest







PostPosted: Sun Feb 11, 2007 4:02 pm     Reply with quote

Hello

Big thank you. Great It works!

I should learn ASM Sad

Thanks again, my problem is now solved!


Greetings, Benny!
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