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

#INT_RDA and PIC16F87
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 7:32 am     Reply with quote

So, where are the other handlers?.
You must _never_ enable an interrupt without a handler for that interrupt present. INT_RB, and INT_RDA in particular, _must_ perform the operations to reset the hardware event that triggered them (read port B, and fetch a character from the UART), or they will trigger _for ever_, and lock the processor.
What you have poster _will_ hang.

Best Wishes
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sat Nov 13, 2010 7:59 am     Reply with quote

Ttelmah wrote:
So, where are the other handlers?.
You must _never_ enable an interrupt without a handler for that interrupt present. INT_RB, and INT_RDA in particular, _must_ perform the operations to reset the hardware event that triggered them (read port B, and fetch a character from the UART), or they will trigger _for ever_, and lock the processor.
What you have poster _will_ hang.

Best Wishes


What do you mean? I can understand. Could you please explanin with example?
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Nov 13, 2010 8:38 am     Reply with quote

Your latest code has an #INT_RDA handler, but is missing #INT_RB, which must be expected to cause your application to hang. The #INT_RDA is performing getc(), as required, but it most likely should also increment the buffer pointer i (and do additional things that you'll need for a buffered receive operation).
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sat Nov 13, 2010 1:26 pm     Reply with quote

FvM wrote:
Your latest code has an #INT_RDA handler, but is missing #INT_RB, which must be expected to cause your application to hang. The #INT_RDA is performing getc(), as required, but it most likely should also increment the buffer pointer i (and do additional things that you'll need for a buffered receive operation).

Code:


#include "16f886.h"
#device *=16 ADC=10

#fuses INTRC_IO,NOWDT,NOPROTECT
#use delay(clock=8000000)
#use rs232(baud=9600, parity=N, xmit=PIN_C6,rcv=PIN_C7, bits=8)

#include "main.h"

#include "bcd.c"
#include "DateTime.c"
#include "Events.c"


#define event_int_timer1         1


BYTE i = 0;
unsigned char eeprom_buffer[32];      // Used for local storage data (EEPROM)
char       last_port_b;
long timeout;
unsigned char   _ServiceType;

#int_RB
void  RB_isr(void)
{
   char port_b;
   char changes;

   port_b = input_b();
   changes = last_port_b ^ port_b;
   last_port_b = port_b;

//********************************************************************************************************//
   
   if ( bit_test(changes,7) && !bit_test(last_port_b,7) )   // High to Low on B7
   {
      if ( !input(PIN_B7) ){
         // do something
      }
       return;
   }
}

#int_RDA
void  RDA_isr(void)
{
   while(!kbhit()&&(++timeout<50000)) // 1/2 second
    delay_us(10);
    if(kbhit()){ 
      eeprom_buffer[i] = getc();
       if ( eeprom_buffer[i] == 0x13 ){
         _ServiceType = eeprom_buffer[1];   
      }   
       i++;
    }else{
       memset(eeprom_buffer, 0x00, sizeof(eeprom_buffer));   
      _ServiceType = 0x00;
      i = 0;
   }

}

#INT_EXT
void ext_isr()
{
   if (!input(PIN_B0) )
   {
      // do something   
   }   
}

#INT_TIMER1
void timer1_isr()
{
   bit_set(int_events, event_int_timer1);
}


#define RED_LED         PIN_A7
#define BLUE_LED        PIN_A6
#define GREEN_LED       PIN_A5

void BlinkRed(int16 nStop ){
   output_high(RED_LED);                     
   delay_ms(nStop);         
   output_low(RED_LED);
}

void BlinkBlue(){
   output_high(BLUE_LED);                     
   delay_ms(1000);         
   output_low(BLUE_LED);
}

void BlinkGreen(int16 nStop){
   output_high(GREEN_LED);                     
   delay_ms(nStop);         
   output_low(GREEN_LED);
}


void main()
{

     disable_interrupts(GLOBAL);   
   
   output_a(0b00000000);
   output_b(0b00000001);
   output_c(0b10011011);
   output_e(0x00);
   
   set_tris_a(0b00000000);
   set_tris_b(0b00000001);
   set_tris_c(0b10011011);
   set_tris_e(0x00);

   port_b_pullups(TRUE);

   setup_adc(ADC_CLOCK_INTERNAL);   
   setup_adc_ports( sAN0|VSS_VDD );
   set_adc_channel(1);
   
   setup_spi(FALSE);
   
   setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_1);   // setup interrupts
   setup_timer_2(T2_DISABLED,0,1);
   
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);
   
   ext_int_edge(0, H_TO_L); // sinyalin dü?en kenarynda kesme olursa interrup olsun (High to Low dü?en kenarda interrup olursa active ol)
   
   setup_oscillator(osc_8mhz);
      
   last_port_b = input_b();
   
   SET_TIMER1(0); // adjust the real time clock

    enable_interrupts(INT_TIMER1);
    enable_interrupts(INT_RB);
    enable_interrupts(INT_EXT);
    enable_interrupts(INT_RDA);
    enable_interrupts(INT_TBE);   
    enable_interrupts(GLOBAL);   
   
    i = 0; // Serail data counter. It was defined at the rs232.
     
   BlinkGreen(1000);

#ignore_warnings 203
   while(TRUE)
   {
      sleep();
   }
}


I have rewrite my acode acording to your insruction, however again it could not enter INT_RB, INT_TIMER1, INT_EXT.

You can see that when i enable all of interrupts it could not came BlinkGreen(1000);

If I disable enable_interrupts(INT_TBE); this code those interrupts (
INT_RB, INT_TIMER1, INT_EXT) are working.

I have changed according to your ex comment add SAMPLE_EARLY but did not change anything.

What can be source of problem ?
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat Nov 13, 2010 1:56 pm     Reply with quote

First, get rid of most of your RDA code.
1) You do not need to test if a character is available, if the interrupt occurs, one _is_.
2) Do _not_ write the the EEPROM in the interrupt. The EEPROM write, takes typically 4mSec. Characters can arrive at just over 1mSec intervals. Delaying in the interrupt for an EEPROM write _will_ overflow the UART. Repeat fifty times, the mantra - _KEEP INTERRUPT HANDLERS FAST, UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING_ - You don't...
3) _Always_ have ERRORS in the UART declaration for he hardware UART. The _only_ occasion not to have this, is if _you_ are handling UART errors. Without this, if the UART overflows, the chip _will_ hang.

Best Wishes
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sat Nov 13, 2010 2:48 pm     Reply with quote

Ttelmah wrote:
First, get rid of most of your RDA code.
1) You do not need to test if a character is available, if the interrupt occurs, one _is_.
2) Do _not_ write the the EEPROM in the interrupt. The EEPROM write, takes typically 4mSec. Characters can arrive at just over 1mSec intervals. Delaying in the interrupt for an EEPROM write _will_ overflow the UART. Repeat fifty times, the mantra - _KEEP INTERRUPT HANDLERS FAST, UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING_ - You don't...
3) _Always_ have ERRORS in the UART declaration for he hardware UART. The _only_ occasion not to have this, is if _you_ are handling UART errors. Without this, if the UART overflows, the chip _will_ hang.

Best Wishes

Code:

Thanks for your comment.

#use rs232(baud=9600, parity=N, xmit=PIN_C6,rcv=PIN_C7, bits=8, ERRORS)


#int_RDA
void  RDA_isr(void)
{
      buffer[i] = getc();
       if ( buffer[i] == 0x13 ){
         _ServiceType = buffer[1];   
      }   
}


I changed my code according to your comment. But did not change anything. If you check my code can comment anything about WHY BlinkGreen(1000) is not working. When i enable INT_TBE it is not going to forward. 16886 Interrupt system does not support FAST, HIGH. After INT_RDA complete it is not going to in the sleep().
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Nov 14, 2010 3:43 am     Reply with quote

I notice that you're applying arbitrary changes to your code, fixing some bugs and add new at other places, one step forward and two steps back.
Previously you had int_rb enabled without an #int_rb handler. Now you have added int_tbe, but are missing the #int_tbe handler. What is next?

It's effectively impossible to help in this situation.
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Nov 14, 2010 4:15 am     Reply with quote

FvM wrote:
I notice that you're applying arbitrary changes to your code, fixing some bugs and add new at other places, one step forward and two steps back.
Previously you had int_rb enabled without an #int_rb handler. Now you have added int_tbe, but are missing the #int_tbe handler. What is next?

It's effectively impossible to help in this situation.


Thanks for your comment. I would want to say that if i did not put #int_tbe and did not enable it was not working INT_RBA interrupt.

At the present i deleted the #int_tbe however does not change anything. In this situation INT_RDA interrupt does not work. If you can send me very simple program with INT_RDA, INT_RB, INT_TIMER1, INT_EXT. I will appreciate.
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Nov 14, 2010 9:41 am     Reply with quote

I'd suspect you almost certainly have hardware problems that need to be fixed, before you have a hope of getting code to work.
1) When you are operating LED's, have you got current limiting resistors in series?.
2) On a 'flash LED' test, check the timing. Do you get the right number of flashes in a minute?.
3) Is the input serial line sitting 'high' when no data is arriving? - if not, the code won't work.
4) If you have an external interrupt in use, is the line feeding this sitting at the correct 'idle' level, when no interrupt is present? - so if you are using H_TO_L is it sitting _above_ the PIC's 'high' input level when no interrupt is occurring, or for L_TO_H, is it sitting below the low level?.

Then, there are examples with the compiler. EX_SISR, shows a reasonable handler for the serial interrupt. Add this to basic code for one other interrupt. Get this working _before_ adding another.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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