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

I think I become mad !

 
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: 19369

View user's profile Send private message

PostPosted: Thu Jul 30, 2015 2:08 pm     Reply with quote

INT_TBE, is called _continuously_ if the transmit buffer is empty. It is at boot.
So with INT_TBE enabled, the code will never work.
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 30, 2015 5:01 pm     Reply with quote

two tips about interrurpts

1) NEVER enable an interrupt unless you have a 'handler'( ISR) for it. The PIC won't know what to do with it.....it'll either crash or do 'strange' things !!

2) Whenever using the hardware UART, ALWAYS add 'ERRORS' to the use rs232(...options...). This will allow the program to carry on when the UART gets more than 3 incoming characters( the limit of the hardware buffer.


Jay
Jean FOUGERON



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

PostPosted: Fri Jul 31, 2015 3:34 am     Reply with quote

Thanks to you two

OK, I need Serial com but I didn't implement it yet, I will do it.

For the time being, I supposed that when there was no #INT_TBE routine nothing hapened, but ... mysteries of PIC
I will add ERRORS

Nevertheless it does not explain why a routine works in a timer and not in main (even when it is surely not necessary to do the job in main because it would be done too often). It would be pleasant to understand it (French say "I don't wand to dead stupid")
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Fri Jul 31, 2015 10:57 am     Reply with quote

The point is that it never gets beyond the interrupt enables. Because there is no INT_TBE handler it'll be looping permanently back trying to find this handler. Except when a timer interrupt triggers, and then the timer interrupt routine gets called.

INT_TBE, says that the USART transmit buffer is empty. The routine then called loads a character to send. Since the buffer _is_ empty at boot, INT_TBE will be called, and unless a character is loaded, will be called again and again.

This is why you must have this interrupt disabled, until you have data to send, and once it is sent, then disable it again.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 31, 2015 11:08 am     Reply with quote

Here is a simple test program to illustrate what Ttelmah says.
Code:
#include <18F4520.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

#define LED1  PIN_B0
#define LED2  PIN_B1

#int_timer1
void timer1_isr(void)
{

output_toggle(LED1);  // This will always blink at about 1 Hz

}

//===================================
void main()
{
output_low(LED1);  // Initially turn both leds off
output_low(LED2);

setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);   
enable_interrupts(INT_TIMER1);
 
enable_interrupts(INT_TBE);  // This will cause continuous interrupts
   
enable_interrupts(GLOBAL);

// The program will never reach the next line and LED2 will never
// turn on, unless you comment out enable_interrupts(INT_TBE).
output_high(LED2);

 while(TRUE);
}
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