Triggering the First UART TX Interrupt..How To?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2010
    Posts
    19

    Default Triggering the First UART TX Interrupt..How To?

    Yesterday I successfully implemented UART RX interrupts using DT Interrupts.

    As far as TX interrupts go, my plan is to use ArrayWrite within my main program to write string messages and A/D readings to the transmit buffer and ArrayRead within the interrupt service routine to transmit character by character.

    Do I have to write the first character of the buffer to the TX register from the main program to get things started or is there a different way to handle this?

  2. #2
    Join Date
    Jan 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Triggering the First UART TX Interrupt..How To?

    OK, after using DT Interrupts to implement TX_INT, I can see that immediately upon enabling the interrupt, I get an interrupt due to TXIF being set (TXREG is empty).
    This would indicate to me that in my main program I would write characters to the TX buffer, enable TX interrupts and within the ISR I would disable TX interrupts upon transmitting the last character.
    I had thought that transmit interrupts might be left enabled such as I am doing with RX interrupts.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Triggering the First UART TX Interrupt..How To?

    Hi,
    The way I usually do it is as follows.

    1) An index pointer is used to point at the character in the array which is to be sent.
    2) When I'm about to start send, set the index pointer to 0 (or whatever) and enable the TX interrupt - interrupt will fire instantly.
    3) In the ISR, grab the byte at location Array[Index], if the grabbed array is my end-of-string byte (usually null) disable interrupt
    4) If it's not the end-of-string byte put it in the TX reg
    5) Increment the index pointer
    6) Leave the ISR

    As you can see the TX interrupt stays enabled untill the end-of-string byte is found, then it's turned off. As soon as the TX reg is free the interrupt will refire and the process starts over at step (3). It keeps going untill the end-of-strin byte is found.

    Obviosuly there are other ways of doing it, if you know how many bytes to send there's no way to check each byte - just keep count of the bytes going out.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Triggering the First UART TX Interrupt..How To?

    Good points about just leaving TX int on,(just don't load any chars), but I use HWserout on same pin if I want to do small serout from basic code line (no arraywrite etc). Then its safer to turn off TXint so the sends don't interfere.
    Don

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Triggering the First UART TX Interrupt..How To?

    Hi Don,
    What I mean is leave it on untill the string at hand is fully sent - then turn it off. If you leave the TX interrupt enabled ALL the time then it would keep firing and firing and firing which would hang up the main application - that's not what I suggest.

    If your main app uses HSEROUT to send and it could do that at the same time as something else using an interrupt driven TX routine then I'd suggest implementing some kind of interlock in such way that the main application isn't allowed to execute HSEROUT if it sees that the TX interrupt is enabled.

    /Henrik.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Triggering the First UART TX Interrupt..How To?

    Henrik,
    Yes, thinking a little further it really does need to be :

    -turn on TXint (in basic), send from INT routine, then disable in TXint when done sending all.
    And just be carefull not to conflict, ie..... turn off one send mode if the other is active, for TX and hwserout.
    (just leaving TXint on without loading chars would just stop the works cold there)(dah)
    Don

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Triggering the First UART TX Interrupt..How To?

    Although it is not directly related, you can do all sorts of neat things by directly writing the interrupt flag registers. For example: If you have a receive
    buffer that needs to be processed quickly, but can't block incoming data, you can have a high-priority receive buffer that sets an (unused) low-priority
    interrupt that does the processing.
    Charles Linquist

  8. #8
    Join Date
    Jan 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Triggering the First UART TX Interrupt..How To?

    Thanks for all the advice.
    I have successfully got it all to work even with a circulating TX buffer that was a pain to get working correctly but I finally got it.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts