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_tbe problems

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








int_tbe problems
PostPosted: Fri Feb 22, 2008 4:06 pm     Reply with quote

Im using a PIC16F688, and compiler v. 4.058.

Ive got a fairly large program, and Im trying to implement the hardware uart. I cant get it to work. Its definitely too much code to post. The problem is that the transmitter buffer interrupt never fires. I made a simple test program using the code wizard, and still no luck getting into int_tbe.

Code:

#include <16F688.h>

#device adc=8
#FUSES INTRC_IO, NOWDT, PUT, MCLR, BROWNOUT_NOSL, NOPROTECT, NOCPD, NOIESO, NOFCMEN
#use delay(clock=8000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A2,bits=8,enable=PIN_A0)

#int_TBE
void  TBE_isr(void)
{
  output_toggle(PIN_C5); // flashes an LED
}



void main()
{

   output_high(PIN_C2);  // latches my power supply
   enable_interrupts(INT_TBE);
   enable_interrupts(GLOBAL);

  while(1)
  {
   
  }
}


Am I misunderstanding how int_tbe works? It should be called over and over again since its not being disabled right?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 4:38 pm     Reply with quote

It only works with the hardware UART. You must specify the hardware
UART pins in the #use rs232() statement. For the 16F688, these are
pins C4 and C5, for Tx and Rx.

The hardware UART module is disabled by default upon power-on reset.
Because you specified non-hardware UART pins, the code to enable it
will not be generated by the compiler. The UART will remain disabled,
and no TBE interrupt will ever occur.
Guest








PostPosted: Sat Feb 23, 2008 11:28 pm     Reply with quote

So if I use the non-hardware uart pins, I have to use the software uart? If the software doesnt use interrupts, how does the receiver know when its receiving a character?
newguy



Joined: 24 Jun 2004
Posts: 1908

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 1:05 am     Reply with quote

It doesn't. You have to continually monitor it.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 3:52 am     Reply with quote

Anonymous wrote:
So if I use the non-hardware uart pins, I have to use the software uart? If the software doesnt use interrupts, how does the receiver know when its receiving a character?

You can connect the software receive pin to an external interrupt trigger pin and set L_TO_H event up. After that, int_ext routine will be called, and you can read the received character after that.
Ttelmah
Guest







PostPosted: Sun Feb 24, 2008 9:45 am     Reply with quote

You would actually want a H_TO_L event. The start bit in TTL asynchronous serial, is a _low_.

Best Wishes
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sun Feb 24, 2008 1:33 pm     Reply with quote

Ttelmah wrote
Quote:
You would actually want a H_TO_L event. The start bit in TTL asynchronous serial, is a _low_.

This is important issue that Ttelmah points out.
I had a 12F683 no hardware (UART ) . I can catch chars in my main loop with the true and tried khbit getc approach so there was no pressing issue forcing an interrupt driven design. Anyway I tried it anyway. The 12F683 has interrupt on change that can be masked down to specific pins. Now the change is both high low and low high. I never got this to work reliably and it might be to do with the dual edge triggering. I abandoned the design since to use the EXT_INT pin would have required a pcb change and the non interrupt code works fine.
Ttelmah any opinion on what is needed to use the interrupt on change assuming its possible?
Ttelmah
Guest







PostPosted: Sun Feb 24, 2008 3:34 pm     Reply with quote

Big problem is speed.
The edge 'event' will occur on the falling edge of the data bit. Even if no other interrupt handlers are present, you are talking something over 30 instruction times to actually reach the handler code. If you want to avoid a 'lockup' condition (if a spike triggers an edge, when no real data is present), you will need to have a kbhit, test then the actual read code. Now this is therefore going to be starting something like 40 instruction times _after_ the start of the character. At 4Mhz, and 9600bps, the 'bit time', is only 104 instructions. The read routine, by default, delays for half a bit time, before starting to sample the data (52 instructions in this example), meaning that you are now _very_ late in the bit. Only a small timing error, is then needed to give data errors....
The latter compilers, have an option 'SAMPLE_EARLY' for the software UART, which is really best used in this situation.
With a faster clock, or a lower baud rate, the problem reduces/disappears.
Remember also, that if you want to use a software UART to transmit data at the same time, the data on this, _will_ be corrupted, as soon as a character is received.

Best Wishes
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sun Feb 24, 2008 5:53 pm     Reply with quote

Thanks Ttelmah for an excellent description. I wish I had tried SAMPLE_EARLY. I'm going to go back and give it a try.
Inside the interrupt on change isr I plan to be doing something this
If ( KBhit()) circ_buff[received_index++]=getc();
I'm at 4mhz on the internal osc rs232 is 9600 baud.
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Thu Nov 11, 2010 12:42 am     Reply with quote

Douglas Kennedy wrote:
Thanks Ttelmah for an excellent description. I wish I had tried SAMPLE_EARLY. I'm going to go back and give it a try.
Inside the interrupt on change isr I plan to be doing something this
If ( KBhit()) circ_buff[received_index++]=getc();
I'm at 4mhz on the internal osc rs232 is 9600 baud.


Dear All,

I have been trying to run below interrupts in my software but it was not working. I am stuck. Anyone can help me solve this problem?

I used the above software and just added
INT_TIMER1, INT_RB, INT_EXT, INT_TBE, INT_RDA.

When I enabled all of them in this case, just INT_RDA and INT_TBE was working however other interrupts was not working. Not fired any time.

I'm using a PIC16F688, and compiler v. 4.058. Also Ttelmah mentioned to use SAMPLE_EARLY but again same stuation.

What can I do ?
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
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