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

RS232 - Blocking PIC

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



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

RS232 - Blocking PIC
PostPosted: Tue Jan 15, 2008 10:07 am     Reply with quote

Hi there. I´m using a pic16F876A to communicate with a PC in RS485 the problem is that when i reset the pic it writes everything in the LCD but when it gets to enable_interrupts(INT_RDA) it stops i even got a blinking led to see the status. If i remove the enable_interrupts(INT_RDA) it works. Can anyone help. Thanks...
Code:
#include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

/////////////////////////////////////////////////////////////

#include "settings.h"
#include "stdlib.h"
#include "keyboard.h"
#include "rs232.h"
#include "card_reader.h"
#include "flexy_lcd.h"
#include "piccomm.h"

/////////////////////////////////////////////////////////////
#define WR PIN_A4
/////////////////////////////////////////////////////////////

void keypad();
void communications();
void init();

/////////////////////////////////////////////////////////////
#INT_RDA
void serial_interrupt(){
   //lcd_putc("I");
   communications();
}
/////////////////////////////////////////////////////////////
#INT_RB
void teclado(){
   keypad();
}
/////////////////////////////////////////////////////////////


void main() {
   setup_adc_ports( NO_ANALOGS );
   lcd_init2();
   atribui_porto();
   rs232_inicializa();
   init_teclado();
   init_cartao();
   init_keypad();
   contem_cartao();
   lcd_putc("\fHELLO\n");
   lcd_putc("WELCOME");
   delay_ms(2000);
   lcd_putc("\f");
   lcd_putc("WAIT...");
   delay_ms(2000);
   lcd_putc("\f");
   init();
   while(true){
      output_high(PIN_A5);
      delay_ms(100);
      output_low(PIN_A5);
      delay_ms(100);
   }
}

void keypad(){

   carrega_buffer();
   delay_ms(PRESSED);
   contem_teclas();
   init_keypad();
}

void communications(){

   descodifica(ReceiveMsg(COM1));

}

void init(){

   output_low(WR);
   enable_interrupts(global);
   enable_interrupts(INT_RB);
   enable_interrupts(int_rda);
}

Ttelmah
Guest







PostPosted: Tue Jan 15, 2008 10:39 am     Reply with quote

You don't show what:
descodifica(ReceiveMsg(COM1));

does.

General comment, I slightly 'scream', when I see calls to routines, unecessarily in interrupts. Interrupts must be short. In (for example), your INT_RB, you are delaying presumably to handle debounce. This implies that interrupts _will_ be disabled in all delays in the main code, and that other interrupts/events cannot be handled for a long time. Don't do this. Make the code for the interrupts, short, and place it in the interrupt handler (you don't want the overhead of extra calls - they all cost _time_). If you want a time delay, program a timer to give this, and immediately exit the routine. Then chck the keys again, when this timer expires. Using calls, also increases the risk that you may call the code from elsewhere, which will then lead to yet more areas with the interrupts disabled.
I'd suspect that the 'descodfica' routine, actually waits for characters. Remember when the interrupt occurs, _just one character_ is waiting. You want to retrieve this, and return ASAP. look at the EX_SISR example, for how to receive data from the interrupt.
As a further comment, how is the RS232 receive line wired?. Remember this must idle high, or the receive interrupt will trigger every character time, with garbage received.

Best Wishes
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 10:58 am     Reply with quote

Thanks for your help Ttelmah my descodifica routine is where i implement my communication protocol with ACKs, NAKs, ENQs, etc... The only thing is even when i start the pic with C6 and C7 without anything connected i get the same error and with this code (it might not be best way to do it Smile ) i´ve got several pics programed to serial interrupts and they´ve been working just fine. I can´t understand the problem, could it be ilegal access of memory? By the way what do you suggest for me to do with the int_rb routine. Thanks again.
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