NuMaker-PFM-M2351 UART1 Programming

Post Reply
niyathishenoy
Posts: 1
Joined: 16 May 2019, 15:37

16 May 2019, 16:57

Hi,
I am trying to print "hello world" using UART1. Pins used for UART1 are PB.6(Rx) and PB7(Tx).But when i open a terminal to view the output there is nothing printed on the serial terminal. Baud rate used is 115200.

I have developed code as follows in main.c:

void SYS_Init(void)
{


/* Enable PLL */
CLK->PLLCTL = CLK_PLLCTL_128MHz_HIRC;

/* Waiting for PLL stable */
while((CLK->STATUS & CLK_STATUS_PLLSTB_Msk) == 0);

/* Set HCLK divider to 2 */
CLK->CLKDIV0 = (CLK->CLKDIV0 & (~CLK_CLKDIV0_HCLKDIV_Msk)) | 1;

/* Switch HCLK clock source to PLL */
CLK->CLKSEL0 = (CLK->CLKSEL0 & (~CLK_CLKSEL0_HCLKSEL_Msk)) | CLK_CLKSEL0_HCLKSEL_PLL;

/* Select IP clock source */
CLK->CLKSEL1 = CLK_CLKSEL1_UART0SEL_HIRC;

/* Enable IP clock */
CLK->APBCLK0 |= CLK_APBCLK0_UART0CKEN_Msk;


/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
//SystemCoreClockUpdate();
PllClock = 128000000; // PLL
SystemCoreClock = 128000000 / 2; // HCLK
CyclesPerUs = 128000000 / 1000000; // For SYS_SysTickDelay()

/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set multi-function pins for UART0 RXD and TXD */
//SYS->GPB_MFPH = (SYS->GPB_MFPH & (~(UART0_RXD_PB12_Msk | UART0_TXD_PB13_Msk))) | UART0_RXD_PB12 | UART0_TXD_PB13;
SYS->GPB_MFPH = (SYS->GPB_MFPH & (~(UART1_RXD_PB6_Msk | UART1_TXD_PB7_Msk))) | UART1_RXD_PB6 | UART1_TXD_PB7;
}

void UART1_Init()
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init UART1 */
/*---------------------------------------------------------------------------------------------------------*/
UART1->LINE = UART_PARITY_NONE | UART_STOP_BIT_1 | UART_WORD_LEN_8;
UART1->BAUD = UART_BAUD_MODE2 | UART_BAUD_MODE2_DIVIDER(__HIRC, 115200);

}
int main()
{
int32_t i;

SYS_UnlockReg();

SYS_Init();

UART1_Init();
UART_Open(UART1,115200);
UART_Write(UART1,(uint8_t *)"Hello\n\r",7);
UART_Close(UART1);
}

Any link for guiding through the same would be helpful.

ycchen
Posts: 2
Joined: 08 Nov 2018, 10:02

17 May 2019, 15:20

The UART1 clock is seems to not enabled in your program.
Please try to enable UART1 clock and set UART1 clcok source by adding the following codes:

/* Select UART1 clock source */
CLK->CLKSEL1 = (CLK->CLKSEL1 & (~CLK_CLKSEL1_UART0SEL_Msk)) | CLK_CLKSEL1_UART0SEL_HIRC;

/* Enable UART1 clock */
CLK->APBCLK0 |= CLK_APBCLK0_UART1CKEN_Msk;

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest