<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>8-bit MicrocontrollersのトピックRe: Interrupt race condition</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187248#M14130</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I just did a simple test and I got different results, the receive data register full interrupt occured first, then the transmit register empty flag.&amp;nbsp;Here is how I setup everything.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This was my main:&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void main(void) {   uint8_t i;      MCU_init(); /* call Device Initialization */   for (i=1;i&amp;lt;21;i++)    // Fill transmit data with 1-20   {      TXData[i-1] = i;   }   SCI1D = TXData[TXCounter];  // Send the first byte   TXCounter++;                   SCI1C2_TCIE = True;         // Enable the transmit complete interrupt   SCI1C2_RIE = True;          // Enable the receive data register full interrupt     while(RXCounter &amp;lt; 20);      // Wait until all data has been received   _asm NOP;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;Then my 2 ISR's:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;__interrupt void SCI1_Rx_ISR(void){  /* Write your interrupt code here ... */   if (SCI1S1_RDRF)   {      RXData[RXCounter] = SCI1D;            RXCounter++;       TestData[TestCounter] = 0x65;          TestCounter++;   }}__interrupt void SCI1_Tx_ISR(void){  /* Write your interrupt code here ... */   if (SCI1S1_TC)   {      SCI1D = TXData[TXCounter];      TXCounter++;       TestData[TestCounter] = 0x1C;      TestCounter++;         }}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;The baud rate used was about 122 baud with the bus running at 16MHz.&amp;nbsp; The first entry in TestData is 0x65 then 0x1C.&amp;nbsp; It alternates back and forth as expected from that point on but 0x65 is the first entry.&amp;nbsp; Another way to get more information on this would be to set a fast free running counter and store the count when the interrupts occur.&amp;nbsp; This would tell you how long after the receive interrupt the transmit complete interrupt fired.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:38:36 GMT</pubDate>
    <dc:creator>allawtterb</dc:creator>
    <dc:date>2020-10-29T09:38:36Z</dc:date>
    <item>
      <title>Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187238#M14120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;I'm using the MC9S08DZ60.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If I connect the SCI2 TX and RX pins to the same line, enable receiver and transmitter, enable Transmission complete interrupt and enable Receiver Interrupt, which interrupt will be served first when sending data? The transmission complete interrupt or the receiver interrupt?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/John&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2008 20:27:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187238#M14120</guid>
      <dc:creator>JohnBarber</dc:creator>
      <dc:date>2008-02-06T20:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187239#M14121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;If you look in the MC9S08DZ60 book, Table 4-1, there is a list of all the interrupts in the 9S08DZ.&lt;/DIV&gt;&lt;DIV&gt;The SCI receiver interrupt has priority 17 and the transmitter has priority 18.&lt;/DIV&gt;&lt;DIV&gt;The lowest number gets the interrupt handled first.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;(the numbers are not shown, you will have to calculate them yourselve. The bottom one, no 0 is the RESET and the highest one, 25 is the RTC.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Ake&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2008 21:19:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187239#M14121</guid>
      <dc:creator>Ake</dc:creator>
      <dc:date>2008-02-06T21:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187240#M14122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Ake,&lt;/DIV&gt;&lt;DIV&gt;I think you are wrong. Suppose TX and RX lines are connected. When the data is sent the Transmission Complete Interrupt is raised. At this point the data is in the receiver shift register. The Receiver interrupt is raised first when the data is shifted to the receiver data register and the RDRF flag is set.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;So the Transmission Complete interrupt will be served first.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/John&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 18:39:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187240#M14122</guid>
      <dc:creator>JohnBarber</dc:creator>
      <dc:date>2008-02-08T18:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187241#M14123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Helllo John,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I think what you are implying is that the transmission complete flag is set &lt;U&gt;before&lt;/U&gt; the receive flag is set , under your specific conditions, probably due to a slight difference in timing within the SCI module.&amp;nbsp; However, should interrupts be globally disabled at the time when &lt;U&gt;both&lt;/U&gt; flags become set, I would assume the interrupt priority situation would exist when interrupts were re-enabled, and the receive interrupt would be serviced first.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;If this is the situation, an ambiguity can exist for your case.&amp;nbsp; Whether the delay difference is "a few microseconds", or a substantial portion of a bit period, would be an interesting question.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;If you require a consistent priority, for example TC, you might first test whether the TC flag is set from within the receive ISR, and process the TC event if so, prior to receive processing.&amp;nbsp; It should be possible to also use this technique to identify the actual amount of delay, by waiting for the receive flag to become set from within the TC ISR, and use the timer count to estimate the delay.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 19:36:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187241#M14123</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-02-08T19:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187242#M14124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;thanks for interesting comments.&lt;/DIV&gt;&lt;DIV&gt;I've done the following experiment:&lt;/DIV&gt;&lt;DIV&gt;From a routine I start the sending of a series of data by writing the first byte to SCI2D.&lt;/DIV&gt;&lt;DIV&gt;The first interrupt that occur is the transmission complete interrupt.&lt;/DIV&gt;&lt;DIV&gt;In the ISR I send data byte 2.&lt;/DIV&gt;&lt;DIV&gt;The next interrupt to occur is transmission complete. In the ISR I&amp;nbsp;send byte 3.&lt;/DIV&gt;&lt;DIV&gt;After that, the first receive interrupt occurs. It obviously lags 2 bytes compared to the TC.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;So my conclusion is that TC interrupt will occur first.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/John&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 20:00:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187242#M14124</guid>
      <dc:creator>JohnBarber</dc:creator>
      <dc:date>2008-02-08T20:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187243#M14125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;This discussion is only valid for a loopback condition.&amp;nbsp; Remember - this is asyncronous communications.&amp;nbsp; There is no way to know when the receive interrupt will occur since you do not know when the remote device will send a byte.&lt;BR /&gt;&lt;BR /&gt;If your interrupt handler is short and only deals with the incomming/outgoing byte long enough to write it to a buffer/read it from a buffer then the interrupt priority between receive and transmit should not make any difference even at the highest data rates.&amp;nbsp; If you must do a lot of processing in your interrupt then you could certainly check the flags for the other interrupt and deal with them - although this sort of defeats the purpose of using interrupts since you are now polling.&lt;BR /&gt;&lt;BR /&gt;Good Luck,&lt;BR /&gt;&lt;BR /&gt;Peter House&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 20:27:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187243#M14125</guid>
      <dc:creator>PeterHouse</dc:creator>
      <dc:date>2008-02-08T20:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187244#M14126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello John,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I am not sure whether you are exiting the ISR each time, or remaining within the ISR.&amp;nbsp; Since all interrupts&amp;nbsp;will normally remain disabled whilst you are within the TC ISR,&amp;nbsp;the receive interrupt cannot occur until you leave the ISR, (but you can still test the RDRF flag).&amp;nbsp; Perhaps another possibility may be that you actually enabled interrupts for both&amp;nbsp;TC and TDRE&lt;/FONT&gt;&lt;FONT size="2"&gt;&amp;nbsp;flags (which use the same vector).&amp;nbsp; If both sources are enabled, a test&amp;nbsp;will be&amp;nbsp;required to determine the source of a particular interrupt.&amp;nbsp; I&amp;nbsp;find it hard to believe there is a two byte lag.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Incidently, when sending a string of characters, and assuming full duplex RS232 interface, it is unusual to utilize the TC interrupt.&amp;nbsp; Since there is double buffering, it is more usual to send the next character when the TDRE flag becomes set.&amp;nbsp; This should result in faster throughput.&amp;nbsp; The TC flag is more useful for half-duplex operation, such as RS485, for determining when to revert from send to receive mode.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;.&lt;/FONT&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 21:03:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187244#M14126</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-02-08T21:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187245#M14127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello bigmac,&lt;/DIV&gt;&lt;DIV&gt;I exit the ISR each time.&lt;/DIV&gt;&lt;DIV&gt;I have only enabled the Transmission Complete Interrupt and the Receiver Interrupt.&lt;/DIV&gt;&lt;DIV&gt;I'm using half duplex RS232. TX and RX pins are connected to each other with a single wire. Transmitted data is read back in the RX ISR.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I can see that the RX interrupt lags 2 bytes.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/John&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 23:00:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187245#M14127</guid>
      <dc:creator>JohnBarber</dc:creator>
      <dc:date>2008-02-08T23:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187246#M14128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;For half duplex operation 2 bytes should be correct.&lt;BR /&gt;&lt;BR /&gt;When you place the byte in the transmit register it takes one byte time to shift it out and simultaneously be shifted in to the receiver.&amp;nbsp; The receiver then turns it around, assume near zero turn around time, and the receiver then shifts its transmit byte out whil the original sender simultaneously receives it and at the end of reception generates an interrupt.&amp;nbsp;&amp;nbsp; These are your two byte times.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Good Luck,&lt;BR /&gt;&lt;BR /&gt;Peter House&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2008 02:53:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187246#M14128</guid>
      <dc:creator>PeterHouse</dc:creator>
      <dc:date>2008-02-09T02:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187247#M14129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;PeterHouse wrote:&lt;BR /&gt;receiver then turns it around, assume near zero turn around time, and the receiver then shifts its transmit byte out whil the original sender simultaneously receives it and at the end of reception generates an interrupt.&amp;nbsp;&amp;nbsp; These are your two byte times.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;I don't see why you are talking about the receiver transmitting anything, I thought we were talking about one chip with a loopback setup.&amp;nbsp; I don't see why there would be a 2 byte delay, I might do a little test with a DZ60 here using a really slow baud rate to test this.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2008 03:52:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187247#M14129</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-02-09T03:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187248#M14130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I just did a simple test and I got different results, the receive data register full interrupt occured first, then the transmit register empty flag.&amp;nbsp;Here is how I setup everything.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This was my main:&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void main(void) {   uint8_t i;      MCU_init(); /* call Device Initialization */   for (i=1;i&amp;lt;21;i++)    // Fill transmit data with 1-20   {      TXData[i-1] = i;   }   SCI1D = TXData[TXCounter];  // Send the first byte   TXCounter++;                   SCI1C2_TCIE = True;         // Enable the transmit complete interrupt   SCI1C2_RIE = True;          // Enable the receive data register full interrupt     while(RXCounter &amp;lt; 20);      // Wait until all data has been received   _asm NOP;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;Then my 2 ISR's:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;__interrupt void SCI1_Rx_ISR(void){  /* Write your interrupt code here ... */   if (SCI1S1_RDRF)   {      RXData[RXCounter] = SCI1D;            RXCounter++;       TestData[TestCounter] = 0x65;          TestCounter++;   }}__interrupt void SCI1_Tx_ISR(void){  /* Write your interrupt code here ... */   if (SCI1S1_TC)   {      SCI1D = TXData[TXCounter];      TXCounter++;       TestData[TestCounter] = 0x1C;      TestCounter++;         }}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;The baud rate used was about 122 baud with the bus running at 16MHz.&amp;nbsp; The first entry in TestData is 0x65 then 0x1C.&amp;nbsp; It alternates back and forth as expected from that point on but 0x65 is the first entry.&amp;nbsp; Another way to get more information on this would be to set a fast free running counter and store the count when the interrupts occur.&amp;nbsp; This would tell you how long after the receive interrupt the transmit complete interrupt fired.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:38:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187248#M14130</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2020-10-29T09:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187249#M14131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;First of all I think that Peter has gone off on the wrong track with his musings. We are just talking about one device simply looped-back here, aren't we?&lt;BR /&gt;&lt;BR /&gt;Also, although I don't have this exact device, I would tend agree with the others and suggest that John is somehow missing something.&lt;BR /&gt;&lt;BR /&gt;The outcome for this is certainly unspecified.&lt;BR /&gt;It should however be a close race and I don't think I would be placing bets either way, but allowing for either outcome.&lt;BR /&gt;&lt;BR /&gt;As for the point that the reciever needs to somehow receive two bytes before it indicates RDRF, this is wrong and the SCI would be severly broken if it were the case.&lt;BR /&gt;&lt;BR /&gt;To the OP, why are you looking at this anyway?&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2008 05:39:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187249#M14131</guid>
      <dc:creator>peg</dc:creator>
      <dc:date>2008-02-09T05:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187250#M14132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;"which interrupt will be served first when sending data?"&lt;BR /&gt;&lt;BR /&gt;That was the question which Ake correctly answered in the first reply. John rebuked the response, as I guess he missed the fully meaning of his question.&lt;BR /&gt;&lt;BR /&gt;As to which interrupt pending flag would be set first, while for a narrow set of carefully defined parameters, may be determinate given inside knowledge of how the hardware was designed, is actually of little relevance and should not be used to design the software. As John tried to point out, in real life there is no way to determine actual arrival of data with respect to it's transmission. One can hardly blame John for assuming a real life application as the bases for his response.&lt;BR /&gt;&lt;BR /&gt;Perhaps "peg" has the right idea in requesting a clarification of the purpose of the inquiry.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2008 07:13:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187250#M14132</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-02-09T07:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt race condition</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187251#M14133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello John,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;FONT size="2"&gt;John Barber wrote:&lt;BR /&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I have only enabled the Transmission Complete Interrupt and the Receiver Interrupt.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I'm using half duplex RS232. TX and RX pins are connected to each other with a single wire. Transmitted data is read back in the RX ISR.&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;There seems to be some confusion whether you are attempting to implement&amp;nbsp; half-duplex transmission, or are simply doing a loop-back test.&lt;/FONT&gt;&lt;/DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;For the half duplex case, you do not need to activate receive interrupts whilst a transmission is in progress, because the received data is of no interest (you already know the data contents).&amp;nbsp; I might tackle the process in the following manner -&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;In the normal state, the reception of data is enabled, using the receive interrupt.&amp;nbsp; The send interrupts, both TDRE and TC would&amp;nbsp;remain disabled.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;When you need to send a data packet, disable the receive interrupt, enable the TDRE interrupt only, and send the first data byte.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Within the send ISR, check that the TDRE flag is set, and send the next data byte.&amp;nbsp; The ISR is called once for each send byte.&amp;nbsp; Prior to sending the final data byte, disable the TDRE interrupt source, and enable the TC interrupt, clear the TC flag, and then send the character.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;When the send ISR is next entered, check that the TC flag is the source, clear the flag, disable TC interrupts, and re-enable the receive interrupt, also clearing the flag (in case it is already set).&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;At the completion of this transmission process, you might check whether the previous problem really exists.&amp;nbsp; If so, would be evidenced by a receive interrupt occurring immediately after the transmission completes, without the presence of an incoming character.&amp;nbsp; Should there still be a problem, its solution&amp;nbsp;would probably require an additional short delay before re-enabling the receive interrupt.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-02-10&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:13 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2008 20:05:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Interrupt-race-condition/m-p/187251#M14133</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-02-10T20:05:40Z</dc:date>
    </item>
  </channel>
</rss>

