xmegs 128A1 serial tx interrupts

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I'm trying to get interrupts on the serial transmitter to work. Its working for the timer and serial receiver, but not for the transmitter.

I do this for the receiver & transmitter to enable interrupts for receive and transmit:

usart_set_rx_interrupt_level( &USARTE0, USART_INT_LVL_MED );
usart_set_tx_interrupt_level( &USARTE0, USART_INT_LVL_MED );

I have ISR's set up for the RXC and TXC vectors and the RXC vector is being used as I get my incoming characters through it OK. The ISR code:

ISR(USARTE0_RXC_vect)
{
   rcvCounter++;
   intChar = USARTE0.DATA;
   dataAvail = 1;
   USARTE0.STATUS |= USART_RXCIF_bm;
};
ISR(USARTE0_TXC_vect)
{
   txcCounter++;
   USARTE0.STATUS |= USART_TXCIF_bm;
};

The txcCounter tracks exactly the rcvCounter value even though I transmit much more than I receive. The rcvCounter tracks exactly the # of characters that I send to the Xmega.

What am I missing? I removed all uses of the stdio-serial stuff, but I haven't taken it out of the project yet. Does that touch the interrupt programming I'm doing to the transmitter? I'm now hand encoding everything that's printed.

Thanks,
madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess all 3 variables used in the ISR are declared as volatile?

Quote:
I transmit much more than I receive
You are not trasmitting anything in the TX ISR. Also you don't need to clear the flags as the chip will do it automatically when the ISR is executed.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John,
Yes, they're volatile.
I'm using a non-interrupt or polled print string routine.
I was expecting that the interrupt will trigger even though that's going on. Maybe that expectation is the problem? The only interrupt that's triggering is the last one, which isn't being followed by another character?

Trying that idea ...

Thanks
madGambol

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John,

That probably was the problem. I changed the code to send one character if the xmtr wasn't busy, and when it was, the character was put into a buffer. The transmit ISR picked the characters from the buffer if the buffer wasn't empty.

The character counters now make sense.

Thanks!

madGambol