Generate the first TXRDY interrupt!

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

Hi!

Maybe this have a simple solution byt I'm a beginner at AVR32. I have set up a interrupt handler for transmitting data on USART1 on a AT32UC3C2512C processor. I'm trying to transmit data from a ring buffer to USART1.

Is it possible to set or clear some bit in some register to generate the first TXRDY interrupt? Without sending a byte first.

Anyone?

Regards

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

Here is some code and i don't know whats wrong but I get TXRDY interrupt as son as enable global interrupt.

regards

#if __GNUC__
__attribute__((__interrupt__))
#elif __ICCAVR32__
__interrupt
#endif
static void usart0_int_handler(void)
{
int c;

usart_read_char(&AVR32_USART0, &c);

usart_write_char(&AVR32_USART0, c);
}

#if __GNUC__
__attribute__((__interrupt__))
#elif __ICCAVR32__
__interrupt
#endif
static void usart1_int_handler(void)
{

// If there is data in the ring buffer send it

}

// Init interrupt
Disable_global_interrupt();
INTC_init_interrupts();

INTC_register_interrupt(&usart0_int_handler, AVR32_USART0_IRQ, AVR32_INTC_INT0);

INTC_register_interrupt(&usart1_int_handler, AVR32_USART1_IRQ, AVR32_INTC_INT0);

// Enable USART0 Rx interrupt.
AVR32_USART0.ier = AVR32_USART_IER_RXRDY_MASK;

// Enable USART1 Tx interrupt.
AVR32_USART1.ier = AVR32_USART_IER_TXRDY_MASK;

// Enable all interrupts.
Enable_global_interrupt();

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

There are typically two types of UART wrt Transmit interrupts.
The first type generates an interrupt whenever the TX holding register (or equiv) is empty, and you usually have to turn off the interrupt when the transmitter is inactive, and make sure it gets turned on when you put a character in the software buffer.
The second type generates an interrupt whenever the TX register BECOMES empty, and you usually have to put the first character in the register to start things going. (on the plus side, you don't have to disable the interrupts when the buffer is empty; it will just stop interrupting.)
I haven't used an AVR32, but the 8bit chips are of the first sort (MOST UARTs are of the first sort.)

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

Do not enable the TXRDY interrupt until you have something to send, and you must disable the TXRDY interrupt when there is no more to send.

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

Thanks!
I have changed my code so I enable RXRDY when I'm starting to transmit data. When all data is transmitted I'm disabling RXRDT in the end of transmit interrupt. It seems to work just fine :) There is something strange in debug mode. When I test RXRDY interrupt I can see bit 0 in CSR change to TRUE during recive interrupt and I can see data in RHR. But when I debug transmit interrupt TXRDY the bit 1 in CSR do not change? I cant see data in THR either? Is this working for someone else?
Regards!

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

Quote:
I have changed my code so I enable RXRDY when I'm starting to transmit data. When all data is transmitted I'm disabling RXRDT
Uhmm., I think you should have written TXRDY

Quote:
There is something strange in debug mode. .... But when I debug transmit interrupt TXRDY the bit 1 in CSR do not change? I cant see data in THR either?
That is what I would expect to see when debugging with JTAG. Read datasheet section 25.6.3.1 to see what happens when the usart transmits.

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

Hi!
Yes I meant TXRDY!

I still have problems with this code. As soon as I enable TXRDY for USART1 the processor only loops in the transmit interrupt and don't execute any other code? I don't think that the USART1 sends data so fast with 9600 baud. I tried to send one byte to USART0 during transmitting with USART1 interrupt but the processor do not execute the RXRDY interrupt. The bit 0 in CSR change to TRUE during recive interrupt but interrupt for USART1 is not executed. I have probably done some simple error but what?
Regards!

[code] #if __GNUC__
__attribute__((__interrupt__))
#elif __ICCAVR32__
__interrupt
#endif
static void usart0_int_handler(void)
{
int c;

// Read recived byte from USART0
usart_read_char(&AVR32_USART0, &c);

// Print the received character to USART0.
usart_write_char(&AVR32_USART0, c);
}

#if __GNUC__
__attribute__((__interrupt__))
#elif __ICCAVR32__
__interrupt
#endif
static void usart1_int_handler(void)
{

// If there is data in the ring buffer send it

AVR32_USART1.thr = (popValue << AVR32_USART_THR_TXCHR_OFFSET) & AVR32_USART_THR_TXCHR_MASK;

// If ring buffer is empty turn off interrupt

AVR32_USART1.idr = AVR32_USART_IDR_TXRDY_MASK;
}

// Disable all interrupts.
Disable_global_interrupt();

// Initialize interrupt vectors.
INTC_init_interrupts();

INTC_register_interrupt(&usart0_int_handler, AVR32_USART0_IRQ, AVR32_INTC_INT0);
INTC_register_interrupt(&usart1_int_handler, AVR32_USART1_IRQ, AVR32_INTC_INT1);

// Enable USART0 Rx interrupt.
AVR32_USART0.ier = AVR32_USART_IER_RXRDY_MASK;

// Enable all interrupts.
Enable_global_interrupt();

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

Thanks!

That is a very good example!

But there is some strange behaviour in AVR Studio 5 debugger when using USART:s trying to transmit and recive with interrupt. But my USART comunication seems to work just fine now.

Regards!