LPC54618 —usart can not work normally?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC54618 —usart can not work normally?

399 Views
Xiaoyh
Contributor III

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef _USART_H_

#define _USART_H_

 

#include "fsl_clock.h"

#include "fsl_iocon.h"

#include "fsl_usart.h"

#include "led.h"

#include "pin_mux.h"

#include "core_cm4.h"

#include <stdbool.h>

#include <string.h>

#include <stdio.h>

#include "fsl_debug_console.h"

 

#define USART3_BAUDRATE 115200

#define USART USART3

#define USART_CLK_FREQ  CLOCK_GetFlexCommClkFreq(3)

 

#define USART3_RX_PORT 2U

#define USART3_TX_PORT 2U

 

#define USART3_RX_PIN 18U

#define USART3_TX_PIN 19U

#define USART3_IRQn FLEXCOMM3_IRQn

#define USART3_IRQHandler   FLEXCOMM3_IRQHandler

void usart_init(void);

void usart_icon_init(void);

#endif

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "usart.h"

void usart_icon_init(void)

{

    CLOCK_EnableClock(kCLOCK_Iocon);

    const uint32_t USART3_RX_CONFIG = (/* Pin is configured as FC0_RXD_SDA_MOSI */

                                         IOCON_PIO_FUNC2 |

                                         /* No addition pin function */

                                         IOCON_PIO_MODE_INACT |

                                         /* Input function is not inverted */

                                         IOCON_PIO_INV_DI |

                                         /* Enables digital function */

                                         IOCON_PIO_DIGITAL_EN |

                                         /* Input filter disabled */

                                         IOCON_PIO_INPFILT_OFF |

                                         /* Standard mode, output slew rate control is enabled */

                                         IOCON_PIO_SLEW_STANDARD |

                                         /* Open drain is disabled */

                                         IOCON_PIO_OPENDRAIN_DI);

    /* PORT2 PIN18 (coords: B13) is configured as FC0_RXD_SDA_MOSI */

    IOCON_PinMuxSet(IOCON, USART3_RX_PORT, USART3_RX_PIN, USART3_RX_CONFIG);

 

    const uint32_t USART3_TX_CONFIG = (/* Pin is configured as FC0_TXD_SCL_MISO */

                                         IOCON_PIO_FUNC2 |

                                         /* No addition pin function */

                                         IOCON_PIO_MODE_INACT |

                                         /* Input function is not inverted */

                                         IOCON_PIO_INV_DI |

                                         /* Enables digital function */

                                         IOCON_PIO_DIGITAL_EN |

                                         /* Input filter disabled */

                                         IOCON_PIO_INPFILT_OFF |

                                         /* Standard mode, output slew rate control is enabled */

                                         IOCON_PIO_SLEW_STANDARD |

                                         /* Open drain is disabled */

                                         IOCON_PIO_OPENDRAIN_DI);

    /* PORT2 PIN19 (coords: A2) is configured as FC3_TXD_SCL_MISO */

    IOCON_PinMuxSet(IOCON, USART3_TX_PORT, USART3_TX_PIN, USART3_TX_CONFIG);

}

/////////////////////////////////////////////////////

uint8_t g_tipString[] =

    "hello world\r\n";

void usart_init(void)

{

    usart_config_t usart3_config;

    CLOCK_AttachClk(kFRO12M_to_FLEXCOMM3);

    usart_icon_init();

    USART_GetDefaultConfig(&usart3_config);

    usart3_config.baudRate_Bps = USART3_BAUDRATE;

    usart3_config.enableTx     = true;

    usart3_config.enableRx     = true;

 

    USART_Init(USART, &usart3_config,USART_CLK_FREQ);

    USART_EnableInterrupts(USART,kUSART_RxLevelInterruptEnable);

    EnableIRQ(USART3_IRQn);

    USART_WriteBlocking(USART,g_tipString , (sizeof(g_tipString) / sizeof(g_tipString[0])) - 1);

}

////////////////////////////////////////////////////////

 uint8_t rxbuff[]="mmm";

volatile uint16_t rxIndex = 0;

void USART3_IRQHandler (void)

{

    uint8_t data = 0;

    /* If new data arrived. */

    if ((kUSART_RxFifoNotEmptyFlag ) & USART_GetStatusFlags(USART))

    {

        data = USART_ReadByte(USART);

        rxbuff[rxIndex++] = data;

        if(data == 0x01){

          while(1);

        }

        if(rxIndex == 3&&(kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(USART)))

        {

          USART_WriteBlocking(USART,rxbuff , rxIndex);

          memset(rxbuff,0,rxIndex);

          rxIndex = 0;

        }

    }

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main(void)

{

   BOARD_BootClockPLL180M();

    usart_init();

    while(1)

    {     

    }

    return 0;  

}

Above is my sorce code.

I am very confuse that the data("hello word\r\n") was send all the time and can not stop forever when I use the function "USART_WriteBlocking" one time with enble usart receive interrupt,the code is stuck in there

while (!(base->STAT & USART_STAT_TXIDLE_MASK))
{
}

But when I disable the usart receive interrprut I find that the data("hello word\r\n") was send one time  when I use the function "USART_WriteBlocking" one time .

I use LPC54618 MCU .

I do not know what make that happened.I am very appreciate it if you give me a solution or find factor make that happed. 

                                                                                                                                     thank you 

 

 

Labels (1)
0 Kudos
0 Replies