<?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>Kinetis Microcontrollers中的主题 Interrupt Driven LPUART Transmits Zeros</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Interrupt-Driven-LPUART-Transmits-Zeros/m-p/805215#M48950</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using the MKL17Z256VLH4 with interrupt-driven LPUART0.&amp;nbsp; When transmitting more than one&amp;nbsp;byte the following bytes are always zero, regardless of what is passed to the subsequent calls of&amp;nbsp;LPUART_WriteByte(), which is in&amp;nbsp;LPUART_TX_RX_IRQHandler().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is just the transmit portion of my ISR:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;if(kLPUART_TxDataRegEmptyFlag &amp;amp; status &amp;amp;&amp;amp; (((LPUART_Type*)UART_SEL[uart])-&amp;gt;CTRL &amp;amp; LPUART_CTRL_TIE_MASK))&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if(TxMsg[uart].pos &amp;lt; TxMsg[uart].length &amp;amp;&amp;amp; SCI_PAR_NONE2 != TxMsg[uart].parity) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LPUART_WriteByte(UART_SEL[uart], TxMsg[uart].data[TxMsg[uart].pos++]); // &amp;lt;&amp;lt; breakpoint here&lt;BR /&gt;&amp;nbsp; &amp;nbsp; } else {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Message is sent.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LPUART_DisableInterrupts(UART_SEL[uart], kLPUART_TxDataRegEmptyInterruptEnable);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LPUART_EnableInterrupts(UART_SEL[uart], kLPUART_TransmissionCompleteInterruptEnable);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I noticed that when I set a breakpoint on the call to LPUART_WriteByte() the data bytes started transmitted correctly (most of the time), so I added a software delay to see what would happen:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;for (int i = 100000; i &amp;gt; 0; i--);&lt;BR /&gt; LPUART_WriteByte(UART_SEL[uart], TxMsg[uart].data[TxMsg[uart].pos++]);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data started coming through (monitored with RealTerm), but it's inconsistent.&amp;nbsp; Clearly there is something wrong here.&amp;nbsp; I've stepped through and verified, using the expressions and memory view windows in KDS, that the data being sent to LPUART_WriteByte() is correct.&amp;nbsp; I've also connected a logic analyzer to the LPUART0 transmit and receive lines and verified that the data coming out of the micro is &lt;STRONG&gt;not&lt;/STRONG&gt; correct.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's clearly something wrong with either the LPUART0 or my use of it.&amp;nbsp; Any insight&amp;nbsp;anyone can offer would be much appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Jul 2018 19:27:07 GMT</pubDate>
    <dc:creator>pcpro178</dc:creator>
    <dc:date>2018-07-11T19:27:07Z</dc:date>
    <item>
      <title>Interrupt Driven LPUART Transmits Zeros</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Interrupt-Driven-LPUART-Transmits-Zeros/m-p/805215#M48950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using the MKL17Z256VLH4 with interrupt-driven LPUART0.&amp;nbsp; When transmitting more than one&amp;nbsp;byte the following bytes are always zero, regardless of what is passed to the subsequent calls of&amp;nbsp;LPUART_WriteByte(), which is in&amp;nbsp;LPUART_TX_RX_IRQHandler().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is just the transmit portion of my ISR:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;if(kLPUART_TxDataRegEmptyFlag &amp;amp; status &amp;amp;&amp;amp; (((LPUART_Type*)UART_SEL[uart])-&amp;gt;CTRL &amp;amp; LPUART_CTRL_TIE_MASK))&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if(TxMsg[uart].pos &amp;lt; TxMsg[uart].length &amp;amp;&amp;amp; SCI_PAR_NONE2 != TxMsg[uart].parity) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LPUART_WriteByte(UART_SEL[uart], TxMsg[uart].data[TxMsg[uart].pos++]); // &amp;lt;&amp;lt; breakpoint here&lt;BR /&gt;&amp;nbsp; &amp;nbsp; } else {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Message is sent.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LPUART_DisableInterrupts(UART_SEL[uart], kLPUART_TxDataRegEmptyInterruptEnable);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LPUART_EnableInterrupts(UART_SEL[uart], kLPUART_TransmissionCompleteInterruptEnable);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I noticed that when I set a breakpoint on the call to LPUART_WriteByte() the data bytes started transmitted correctly (most of the time), so I added a software delay to see what would happen:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;for (int i = 100000; i &amp;gt; 0; i--);&lt;BR /&gt; LPUART_WriteByte(UART_SEL[uart], TxMsg[uart].data[TxMsg[uart].pos++]);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data started coming through (monitored with RealTerm), but it's inconsistent.&amp;nbsp; Clearly there is something wrong here.&amp;nbsp; I've stepped through and verified, using the expressions and memory view windows in KDS, that the data being sent to LPUART_WriteByte() is correct.&amp;nbsp; I've also connected a logic analyzer to the LPUART0 transmit and receive lines and verified that the data coming out of the micro is &lt;STRONG&gt;not&lt;/STRONG&gt; correct.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's clearly something wrong with either the LPUART0 or my use of it.&amp;nbsp; Any insight&amp;nbsp;anyone can offer would be much appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2018 19:27:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Interrupt-Driven-LPUART-Transmits-Zeros/m-p/805215#M48950</guid>
      <dc:creator>pcpro178</dc:creator>
      <dc:date>2018-07-11T19:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt Driven LPUART Transmits Zeros</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Interrupt-Driven-LPUART-Transmits-Zeros/m-p/805216#M48951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jim&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't see anything obvious - the following is the same LPUART interrupt handler in the uTasker project (used in many KL17/KL27 products and no problems experienced):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;// Generic LPUART interrupt handler&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;//&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;static&lt;/SPAN&gt; __interrupt &lt;SPAN class="keyword token"&gt;void&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;_LPUART_interrupt&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;KINETIS_LPUART_CONTROL &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;ptrLPUART&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt; LPUART_Reference&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;// generic LPUART interrupt handler&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;long&lt;/SPAN&gt; ulState &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; ptrLPUART&lt;SPAN class="operator token"&gt;-&amp;gt;&lt;/SPAN&gt;LPUART_STAT&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;// status register on entry to the interrupt routine&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ulState &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; LPUART_STAT_TDRE&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; ptrLPUART&lt;SPAN class="operator token"&gt;-&amp;gt;&lt;/SPAN&gt;LPUART_CTRL&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;// if transmit buffer is empty and the transmit interrupt is enabled&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token function"&gt;fnSciTxByte&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;QUEUE_LIMIT&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;LPUART_Reference&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;// transmit data empty interrupt - write next byte, if waiting&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fnSCITxByte() does the same as yours (feeds the next byte or disables further interrupts).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, when I look again I would review carefully the brackets in&lt;/P&gt;&lt;P&gt;if(kLPUART_TxDataRegEmptyFlag &amp;amp; status &amp;amp;&amp;amp; (((LPUART_Type*)UART_SEL[uart])-&amp;gt;CTRL &amp;amp; LPUART_CTRL_TIE_MASK))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It sounds as though your interrupt may be reentering faster than you expect and thus cause you to overrun the output buffer if this were not right (check the interrupt with a port toggle at each occurrence and maybe you will have surprised - it should reenter only once per character (somewhere around the last data bit transmission).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;EM&gt;uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)&lt;/EM&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff;"&gt;&lt;EM&gt;&lt;SPAN&gt;Kinetis: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #3366ff;"&gt;uTasker - for more performance and faster, cheaper product development&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2018 22:49:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Interrupt-Driven-LPUART-Transmits-Zeros/m-p/805216#M48951</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2018-07-11T22:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Interrupt Driven LPUART Transmits Zeros</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Interrupt-Driven-LPUART-Transmits-Zeros/m-p/805217#M48952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Mark, for the good suggestions.&amp;nbsp; It turned out that a message buffer was being shared by both the transmit and receive sides of the&amp;nbsp;application (inherited code from my predecessor), and they were stomping on each other.&amp;nbsp; Modifying the code to use separate buffers for transmit and receive resolved the problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2018 11:49:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Interrupt-Driven-LPUART-Transmits-Zeros/m-p/805217#M48952</guid>
      <dc:creator>pcpro178</dc:creator>
      <dc:date>2018-07-13T11:49:41Z</dc:date>
    </item>
  </channel>
</rss>

