<?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 lpc55s16 usart  read related issue in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc55s16-usart-read-related-issue/m-p/2014964#M57425</link>
    <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;i am using lpc55s16 usart interrupt sample code in this code i can read 16 bytes data correct and i want to read more than 16 bytes but i got some garbage value while print in console&amp;nbsp;&lt;/P&gt;&lt;P&gt;i change&amp;nbsp;DEMO_RING_BUFFER_SIZE&amp;nbsp; also but still getting same data&lt;/P&gt;&lt;P&gt;can you guide me how to read and print correct data on console .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code :&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;* Copyright (c) 2016, Freescale Semiconductor, Inc.&lt;BR /&gt;* Copyright 2016-2017 NXP&lt;BR /&gt;* All rights reserved.&lt;BR /&gt;*&lt;BR /&gt;* SPDX-License-Identifier: BSD-3-Clause&lt;BR /&gt;*/&lt;/P&gt;&lt;P&gt;#include "pin_mux.h"&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "fsl_usart.h"&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;BR /&gt;#include "fsl_power.h"&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt;* Definitions&lt;BR /&gt;******************************************************************************/&lt;BR /&gt;#define DEMO_USART USART0&lt;BR /&gt;#define DEMO_USART_CLK_SRC kCLOCK_Flexcomm0&lt;BR /&gt;#define DEMO_USART_CLK_FREQ CLOCK_GetFlexCommClkFreq(0U)&lt;BR /&gt;#define DEMO_USART_IRQHandler FLEXCOMM0_IRQHandler&lt;BR /&gt;#define DEMO_USART_IRQn FLEXCOMM0_IRQn&lt;/P&gt;&lt;P&gt;/*! @brief Ring buffer size (Unit: Byte). */&lt;BR /&gt;#define DEMO_RING_BUFFER_SIZE 16&lt;/P&gt;&lt;P&gt;/*! @brief Ring buffer to save received data. */&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Prototypes&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Variables&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;uint8_t g_tipString[] =&lt;BR /&gt;"Usart functional API interrupt example\r\nBoard receives characters then sends them out\r\nNow please input:\r\n";&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Ring buffer for data input and output, in this example, input data are saved&lt;BR /&gt;to ring buffer in IRQ handler. The main function polls the ring buffer status,&lt;BR /&gt;if there are new data, then send them out.&lt;BR /&gt;Ring buffer full: (((rxIndex + 1) % DEMO_RING_BUFFER_SIZE) == txIndex)&lt;BR /&gt;Ring buffer empty: (rxIndex == txIndex)&lt;BR /&gt;*/&lt;BR /&gt;uint8_t demoRingBuffer[DEMO_RING_BUFFER_SIZE];&lt;BR /&gt;volatile uint16_t txIndex; /* Index of the data to send out. */&lt;BR /&gt;volatile uint16_t rxIndex; /* Index of the memory to save new arrived data. */&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Code&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;void DEMO_USART_IRQHandler(void)&lt;BR /&gt;{&lt;BR /&gt;uint8_t data;&lt;/P&gt;&lt;P&gt;/* If new data arrived. */&lt;BR /&gt;if ((kUSART_RxFifoNotEmptyFlag | kUSART_RxError) &amp;amp; USART_GetStatusFlags(DEMO_USART))&lt;BR /&gt;{&lt;BR /&gt;data = USART_ReadByte(DEMO_USART);&lt;BR /&gt;/* If ring buffer is not full, add data to ring buffer. */&lt;BR /&gt;if (((rxIndex + 1) % DEMO_RING_BUFFER_SIZE) != txIndex)&lt;BR /&gt;{&lt;BR /&gt;demoRingBuffer[rxIndex] = data;&lt;BR /&gt;rxIndex++;&lt;BR /&gt;rxIndex %= DEMO_RING_BUFFER_SIZE;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;//printf("%s \n",demoRingBuffer);&lt;BR /&gt;SDK_ISR_EXIT_BARRIER;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/*!&lt;BR /&gt;* @brief Main function&lt;BR /&gt;*/&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt;usart_config_t config;&lt;/P&gt;&lt;P&gt;/* set BOD VBAT level to 1.65V */&lt;BR /&gt;POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);&lt;BR /&gt;/* attach 12 MHz clock to FLEXCOMM0 (debug console) */&lt;BR /&gt;CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);&lt;/P&gt;&lt;P&gt;BOARD_InitBootPins();&lt;BR /&gt;BOARD_InitBootClocks();&lt;BR /&gt;BOARD_InitDebugConsole();&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;* config.baudRate_Bps = 115200U;&lt;BR /&gt;* config.parityMode = kUSART_ParityDisabled;&lt;BR /&gt;* config.stopBitCount = kUSART_OneStopBit;&lt;BR /&gt;* config.loopback = false;&lt;BR /&gt;* config.enableTxFifo = false;&lt;BR /&gt;* config.enableRxFifo = false;&lt;BR /&gt;*/&lt;BR /&gt;USART_GetDefaultConfig(&amp;amp;config);&lt;BR /&gt;config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;&lt;BR /&gt;config.enableTx = true;&lt;BR /&gt;config.enableRx = true;&lt;/P&gt;&lt;P&gt;USART_Init(DEMO_USART, &amp;amp;config, DEMO_USART_CLK_FREQ);&lt;/P&gt;&lt;P&gt;/* Send g_tipString out. */&lt;BR /&gt;USART_WriteBlocking(DEMO_USART, g_tipString, (sizeof(g_tipString) / sizeof(g_tipString[0])) - 1);&lt;/P&gt;&lt;P&gt;/* Enable RX interrupt. */&lt;BR /&gt;USART_EnableInterrupts(DEMO_USART, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);&lt;BR /&gt;EnableIRQ(DEMO_USART_IRQn);&lt;/P&gt;&lt;P&gt;while (1)&lt;BR /&gt;{&lt;BR /&gt;/* Send data only when USART TX register is empty and ring buffer has data to send out. */&lt;BR /&gt;while ((kUSART_TxFifoNotFullFlag &amp;amp; USART_GetStatusFlags(DEMO_USART)) &amp;amp;&amp;amp; (rxIndex != txIndex))&lt;BR /&gt;{&lt;BR /&gt;USART_WriteByte(DEMO_USART, demoRingBuffer[txIndex]);&lt;BR /&gt;txIndex++;&lt;BR /&gt;txIndex %= DEMO_RING_BUFFER_SIZE;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Dharm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Dec 2024 06:45:43 GMT</pubDate>
    <dc:creator>firmwareteam</dc:creator>
    <dc:date>2024-12-17T06:45:43Z</dc:date>
    <item>
      <title>lpc55s16 usart  read related issue</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc55s16-usart-read-related-issue/m-p/2014964#M57425</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;i am using lpc55s16 usart interrupt sample code in this code i can read 16 bytes data correct and i want to read more than 16 bytes but i got some garbage value while print in console&amp;nbsp;&lt;/P&gt;&lt;P&gt;i change&amp;nbsp;DEMO_RING_BUFFER_SIZE&amp;nbsp; also but still getting same data&lt;/P&gt;&lt;P&gt;can you guide me how to read and print correct data on console .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code :&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;* Copyright (c) 2016, Freescale Semiconductor, Inc.&lt;BR /&gt;* Copyright 2016-2017 NXP&lt;BR /&gt;* All rights reserved.&lt;BR /&gt;*&lt;BR /&gt;* SPDX-License-Identifier: BSD-3-Clause&lt;BR /&gt;*/&lt;/P&gt;&lt;P&gt;#include "pin_mux.h"&lt;BR /&gt;#include "board.h"&lt;BR /&gt;#include "fsl_usart.h"&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;BR /&gt;#include "fsl_power.h"&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt;* Definitions&lt;BR /&gt;******************************************************************************/&lt;BR /&gt;#define DEMO_USART USART0&lt;BR /&gt;#define DEMO_USART_CLK_SRC kCLOCK_Flexcomm0&lt;BR /&gt;#define DEMO_USART_CLK_FREQ CLOCK_GetFlexCommClkFreq(0U)&lt;BR /&gt;#define DEMO_USART_IRQHandler FLEXCOMM0_IRQHandler&lt;BR /&gt;#define DEMO_USART_IRQn FLEXCOMM0_IRQn&lt;/P&gt;&lt;P&gt;/*! @brief Ring buffer size (Unit: Byte). */&lt;BR /&gt;#define DEMO_RING_BUFFER_SIZE 16&lt;/P&gt;&lt;P&gt;/*! @brief Ring buffer to save received data. */&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Prototypes&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Variables&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;uint8_t g_tipString[] =&lt;BR /&gt;"Usart functional API interrupt example\r\nBoard receives characters then sends them out\r\nNow please input:\r\n";&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;Ring buffer for data input and output, in this example, input data are saved&lt;BR /&gt;to ring buffer in IRQ handler. The main function polls the ring buffer status,&lt;BR /&gt;if there are new data, then send them out.&lt;BR /&gt;Ring buffer full: (((rxIndex + 1) % DEMO_RING_BUFFER_SIZE) == txIndex)&lt;BR /&gt;Ring buffer empty: (rxIndex == txIndex)&lt;BR /&gt;*/&lt;BR /&gt;uint8_t demoRingBuffer[DEMO_RING_BUFFER_SIZE];&lt;BR /&gt;volatile uint16_t txIndex; /* Index of the data to send out. */&lt;BR /&gt;volatile uint16_t rxIndex; /* Index of the memory to save new arrived data. */&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt;* Code&lt;BR /&gt;******************************************************************************/&lt;/P&gt;&lt;P&gt;void DEMO_USART_IRQHandler(void)&lt;BR /&gt;{&lt;BR /&gt;uint8_t data;&lt;/P&gt;&lt;P&gt;/* If new data arrived. */&lt;BR /&gt;if ((kUSART_RxFifoNotEmptyFlag | kUSART_RxError) &amp;amp; USART_GetStatusFlags(DEMO_USART))&lt;BR /&gt;{&lt;BR /&gt;data = USART_ReadByte(DEMO_USART);&lt;BR /&gt;/* If ring buffer is not full, add data to ring buffer. */&lt;BR /&gt;if (((rxIndex + 1) % DEMO_RING_BUFFER_SIZE) != txIndex)&lt;BR /&gt;{&lt;BR /&gt;demoRingBuffer[rxIndex] = data;&lt;BR /&gt;rxIndex++;&lt;BR /&gt;rxIndex %= DEMO_RING_BUFFER_SIZE;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;//printf("%s \n",demoRingBuffer);&lt;BR /&gt;SDK_ISR_EXIT_BARRIER;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/*!&lt;BR /&gt;* @brief Main function&lt;BR /&gt;*/&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt;usart_config_t config;&lt;/P&gt;&lt;P&gt;/* set BOD VBAT level to 1.65V */&lt;BR /&gt;POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);&lt;BR /&gt;/* attach 12 MHz clock to FLEXCOMM0 (debug console) */&lt;BR /&gt;CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);&lt;/P&gt;&lt;P&gt;BOARD_InitBootPins();&lt;BR /&gt;BOARD_InitBootClocks();&lt;BR /&gt;BOARD_InitDebugConsole();&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;* config.baudRate_Bps = 115200U;&lt;BR /&gt;* config.parityMode = kUSART_ParityDisabled;&lt;BR /&gt;* config.stopBitCount = kUSART_OneStopBit;&lt;BR /&gt;* config.loopback = false;&lt;BR /&gt;* config.enableTxFifo = false;&lt;BR /&gt;* config.enableRxFifo = false;&lt;BR /&gt;*/&lt;BR /&gt;USART_GetDefaultConfig(&amp;amp;config);&lt;BR /&gt;config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;&lt;BR /&gt;config.enableTx = true;&lt;BR /&gt;config.enableRx = true;&lt;/P&gt;&lt;P&gt;USART_Init(DEMO_USART, &amp;amp;config, DEMO_USART_CLK_FREQ);&lt;/P&gt;&lt;P&gt;/* Send g_tipString out. */&lt;BR /&gt;USART_WriteBlocking(DEMO_USART, g_tipString, (sizeof(g_tipString) / sizeof(g_tipString[0])) - 1);&lt;/P&gt;&lt;P&gt;/* Enable RX interrupt. */&lt;BR /&gt;USART_EnableInterrupts(DEMO_USART, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);&lt;BR /&gt;EnableIRQ(DEMO_USART_IRQn);&lt;/P&gt;&lt;P&gt;while (1)&lt;BR /&gt;{&lt;BR /&gt;/* Send data only when USART TX register is empty and ring buffer has data to send out. */&lt;BR /&gt;while ((kUSART_TxFifoNotFullFlag &amp;amp; USART_GetStatusFlags(DEMO_USART)) &amp;amp;&amp;amp; (rxIndex != txIndex))&lt;BR /&gt;{&lt;BR /&gt;USART_WriteByte(DEMO_USART, demoRingBuffer[txIndex]);&lt;BR /&gt;txIndex++;&lt;BR /&gt;txIndex %= DEMO_RING_BUFFER_SIZE;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Dharm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 06:45:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpc55s16-usart-read-related-issue/m-p/2014964#M57425</guid>
      <dc:creator>firmwareteam</dc:creator>
      <dc:date>2024-12-17T06:45:43Z</dc:date>
    </item>
  </channel>
</rss>

