Page 1 of 1

NuMaker-PFM-M2351 UART1 Programming

Posted: 16 May 2019, 16:57
by niyathishenoy
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.

Re: NuMaker-PFM-M2351 UART1 Programming

Posted: 17 May 2019, 15:20
by ycchen
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;

NuMaker PFM M2351 UART1 Programming

Posted: 15 Aug 2019, 03:19
by Kamignof
I can not take part now in discussion - there is no free time. Very soon I will necessarily express the opinion.


If you liked this write-up and you would like to receive additional information concerning Can I bet on esports kindly check out our web site

NuMaker PFM M2351 UART1 Programming

Posted: 05 Sep 2019, 23:31
by CharlesRek
One more question: what would be the procedure of firmware uploading in case of using a USB-UART converter that have CTS/RTS but no DSR/DTR? We only have that kind by now. Hope to get a more complete one soon.