<?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>topic C Program to Convert String to ASCII and Send Them Via UART in KL25Z in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/C-Program-to-Convert-String-to-ASCII-and-Send-Them-Via-UART-in/m-p/2094927#M67534</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I'm trying to design a communication system. My KL25Z is supposed to receive some data in UART, process them and transmit them again. Since I was facing some problems, I decided to isolate the project and found that the problem is from KL25Z side.&amp;nbsp; The characters that are shown on the serial terminal is garbage and unprintable; although the baud rates are set and both sides have 8N1 UART. I'll share the corresponding code parts below (I've attached the full codes as well if it helps):&lt;/P&gt;&lt;P&gt;// Transmit one byte via UART2&lt;BR /&gt;void UART2_Transmit(uint8_t data) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!(UART2-&amp;gt;S1 &amp;amp; UART_S1_TDRE_MASK)) {} // Wait until transmit buffer is empty&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART2-&amp;gt;D = data;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Blink_Blue();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Function to write data to UART2&lt;BR /&gt;void UART_Write(const char* data) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (*data) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART2_Transmit((uint8_t) *data); // Transmit data via UART2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data++;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;int main(void) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART2_Init();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Blink_Red();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART_Write("K");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART_Write("L");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART_Write("\n");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-PRODUCT title="FRDM-KL25Z" id="FRDM-KL25Z"&gt;&lt;/LI-PRODUCT&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 11 May 2025 19:43:04 GMT</pubDate>
    <dc:creator>ElectroDesi9n</dc:creator>
    <dc:date>2025-05-11T19:43:04Z</dc:date>
    <item>
      <title>C Program to Convert String to ASCII and Send Them Via UART in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/C-Program-to-Convert-String-to-ASCII-and-Send-Them-Via-UART-in/m-p/2094927#M67534</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I'm trying to design a communication system. My KL25Z is supposed to receive some data in UART, process them and transmit them again. Since I was facing some problems, I decided to isolate the project and found that the problem is from KL25Z side.&amp;nbsp; The characters that are shown on the serial terminal is garbage and unprintable; although the baud rates are set and both sides have 8N1 UART. I'll share the corresponding code parts below (I've attached the full codes as well if it helps):&lt;/P&gt;&lt;P&gt;// Transmit one byte via UART2&lt;BR /&gt;void UART2_Transmit(uint8_t data) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!(UART2-&amp;gt;S1 &amp;amp; UART_S1_TDRE_MASK)) {} // Wait until transmit buffer is empty&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART2-&amp;gt;D = data;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Blink_Blue();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Function to write data to UART2&lt;BR /&gt;void UART_Write(const char* data) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (*data) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART2_Transmit((uint8_t) *data); // Transmit data via UART2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data++;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;int main(void) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART2_Init();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Blink_Red();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART_Write("K");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART_Write("L");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Delay(20000);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UART_Write("\n");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-PRODUCT title="FRDM-KL25Z" id="FRDM-KL25Z"&gt;&lt;/LI-PRODUCT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 May 2025 19:43:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/C-Program-to-Convert-String-to-ASCII-and-Send-Them-Via-UART-in/m-p/2094927#M67534</guid>
      <dc:creator>ElectroDesi9n</dc:creator>
      <dc:date>2025-05-11T19:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: C Program to Convert String to ASCII and Send Them Via UART in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/C-Program-to-Convert-String-to-ASCII-and-Send-Them-Via-UART-in/m-p/2097399#M67543</link>
      <description>&lt;P&gt;I'm not super familiar with the KL25 family (but am with several other Kinetis devices). Here's a couple of things to check.&lt;/P&gt;&lt;P&gt;Remove this line:&lt;/P&gt;&lt;PRE&gt;UART2-&amp;gt;C4 = (UART2-&amp;gt;C4 &amp;amp; ~UARTLP_C4_OSR_MASK) | UARTLP_C4_OSR(&lt;SPAN class=""&gt;15&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;P&gt;That is for the low power UART's and not UART's 1-2.&lt;/P&gt;&lt;P&gt;I also 'or' the masks just so there is no confusion of the order of operations:&lt;/P&gt;&lt;PRE&gt;UART2-&amp;gt;C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK);&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;A scope would go a long ways in figuring out what is wrong&amp;nbsp; If you're seeing garbage in a terminal then it's likely a clock issue.&amp;nbsp; The bus clock is usually (not necessarily) half the CPU clock for slower devices.&amp;nbsp; If your CPU clock is running at 48 MHz you can look at the SIM-&amp;gt;CLKDIV[OUTDIV4] register.&amp;nbsp; That sets the bus clock.&amp;nbsp; it should be 001 (for the OUTDIV4 section).&lt;BR /&gt;&lt;BR /&gt;Also make sure both devices are using the same voltage.&amp;nbsp; &lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 14:00:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/C-Program-to-Convert-String-to-ASCII-and-Send-Them-Via-UART-in/m-p/2097399#M67543</guid>
      <dc:creator>mccoder</dc:creator>
      <dc:date>2025-05-14T14:00:12Z</dc:date>
    </item>
  </channel>
</rss>

