LPC18xx UART0 cannot work

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC18xx UART0 cannot work

2,393 次查看
yuanbinzhou
Contributor II

Hi all,

I am currently using LPC1837 processor in my project and try to use UART0 to debug . Unfortunatelly it cannot work. In my project, I use uart0 to send messages to my computer visa usb-uart cable and initialize the uart register as below:

LPC_CCU1->CLK_M3_GPIO_CFG |= 0x01;
while (!(LPC_CCU1->CLK_M3_GPIO_STAT & 0x01));

/* Enable USART0 peripheral clock */
LPC_CCU2->CLK_APB0_USART0_CFG |= 0x01;
while (!(LPC_CCU2->CLK_APB0_USART0_STAT & 0x01));

/* Enable USART0 register interface clock */
LPC_CCU1->CLK_M3_USART0_CFG |= 0x01;
while (!(LPC_CCU1->CLK_M3_USART0_STAT & 0x01));

/* Init GPIO pins */
LPC_SCU->SFSP2_0 = (1 << 6) | /* Input buffer enabled */
(1 << 4) | /* Pull-up disabled */
(1 << 0) ; /* Pin P2_0 used as U0_TXD */

LPC_SCU->SFSP2_1 = (1 << 6) | /* Input buffer enabled */
(1 << 4) | /* Pull-up disabled */
(1 << 0) ; /* Pin P2_1 used as U0_RXD */

/* Init USART0 */
uart->USART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
uart->USART->DLL = 0x06; /* 115200 Baudrate @ 12 MHz IRC */
uart->USART->DLM = 0x00;
uart->USART->FDR = 0xC1;
uart->USART->LCR = 0x03; /* DLAB = 0 */
/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(uart->USART_IRQn, ((0x01 << 3) | 0x01));

/* Enable Interrupt for UART channel */
NVIC_EnableIRQ(uart->USART_IRQn);

to send data:

while (!(uart->USART->LSR & 0x20));
uart->USART->THR = c;

c here stands for data want to be sent.

Platform:Keil Uvision4

Outcome:No any messages in the ternimal.

It is really strange that there is not any messages in the ternimal since the function of GPIO has been correctly set. What is wrong with my codes?

标签 (1)
标记 (2)
0 项奖励
回复
13 回复数

876 次查看
pranavkolte
Contributor I

pranavkolte_0-1703148136605.png

It gives this response

pranavkolte_1-1703148200339.png

And this code 

 

0 项奖励
回复

884 次查看
pranavkolte
Contributor I

UART on LPC18S37  always responding the below data as I am sending 0xAA can u please help me with this

 

 M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M▒Ս▒M

0 项奖励
回复

1,749 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yuanbin Zhou,

   Please refer to our LPC1837 lpcopen code at first.

   You can download the IAR and MDK lpcopen code for LPCxpresso 1837 board from this link:

http://www.nxp.com/assets/downloads/data/en/software/lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837.zip 

UART0 code is in folder: lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\iar\periph_uart

The default uart0 pin is using :  P6_4 as UART0_TXD, P2_1 as UART0_RXD.

 If you want to use P2_0 as UART0_TXD, you can modify the Board_UART_Init function in board.c like this:

pastedImage_2.png

Then build the lib and the uart project again.

This is test result with lpcxpresso 1837:

pastedImage_3.png

Wish it helps you!

If you still have question after using our official code, please let me know.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,749 次查看
yuanbinzhou
Contributor II

Hi Kerry Zhou,

I have tried to build uart demo downloaded from the link you have posted trhough IAR IDE and to be honest I am not familiar with it. Unfortunately ONE MISTAKE has encountered during the link process and I did not alter any source codes and configurations of the project. Could you please kindly help me. The output information is:

Fatal Error[Li001]: could not open file "C:\Users\xxx\Downloads\lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\iar\lpc_board_nxp_lpcxpresso_1837\iar_output\Exe\ lib_lpc_board_nxp_lpcxpresso_1837.a"

Platform:IAR Embedded Workbench for ARM 7.70.1.11486

0 项奖励
回复

1,749 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yuanbin Zhou,

   Please follow my step, and try again to build the project.

1. Open folder:lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\iar\periph_examples

2.Build lib_lpc_board at first, then build lib_lpc_chip, at last build uart.

pastedImage_3.png

Your problem is caused by the lib, you didn't build the lib at first.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,749 次查看
yuanbinzhou
Contributor II

One more question is that how can I port the uart driver into CMSIS library

0 项奖励
回复

1,749 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yuanbin Zhou,

  I find some CMSIS driver from LPC183x series.

LPC18xx CMSIS-Compliant Standard Peripheral Firmware Driver Library (Keil, IAR) | www.LPCware.com 

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

1,749 次查看
yuanbinzhou
Contributor II

Hi Kerry Zhou,

Thanks for your help. Could you please give me a very simple example to make UART working(e.g. Files that write register s directly except the files that call library although that is not very hard to understand. However I am afraid that I neglected something important in the files ). I have read the manual MANY MANY MANY times and use very similar code as the example. But in my code, UART0 still cannot work.  What should I do? Which code should be written? Set the pin? UART Configuration?

0 项奖励
回复

1,749 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hello Yuanbin Zhou,

  Sorry for my later reply.

  Actually, the simple code you also can refer to the lpcopen code.

  I have modify the lpcopen code like this:

#include "chip.h"
#include "board.h"

/*****************************************************************************
 * Private types/enumerations/variables
 ****************************************************************************/
#define UARTNum 0


#define LPC_UART LPC_USART0
#define UARTx_IRQn  USART0_IRQn

int main(void)
{
  unsigned int i,j;
    SystemCoreClockUpdate();
    Board_Init();
    Board_UART_Init(LPC_UART);

    Chip_UART_Init(LPC_UART);
    Chip_UART_SetBaud(LPC_UART, 115200);
    Chip_UART_ConfigData(LPC_UART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT); /* Default 8-N-1 */

    /* Enable UART Transmit */
    Chip_UART_TXEnable(LPC_UART);

       while(1)
       {
         for(i=0;i<100;i++) for(j=0;j<65535;j++);
        while((Chip_UART_ReadLineStatus(LPC_USART0) & UART_LSR_THRE) != 0)
            LPC_USART0->THR = (uint32_t)0X55;
      
       }

}

It is just send 0X55 with 115200bps in UART0, PIO2_0 and PIO2-1.

I also attached my test project for your reference, and the following picture is the test result:

pastedImage_1.png

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

1,749 次查看
yuanbinzhou
Contributor II

Hi Kerry Zhou,

Thanks very much for your reply. With your help, UART0 is running well as expected by using IAR IDE. However, my team and I would prefer to use Keil uVision and I am trying to build project through Keil uVision5. I followed the steps the same as IAR IDE as you guided, that is

1. Open folder:lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\keil\periph_examples
2.Build lib_lpc_board at first, then build lib_lpc_chip, at last build uart.

However it get the following messages when I build the lib_lpc_board project:

Error: C4065E: type of input file 'C:\Users\credo\Downloads\lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\keil\periph_sdmmc\RTE' unknown
compiling sdmmc.c...
Error: C4065E: type of input file 'C:\Users\credo\Downloads\lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\keil\periph_sdmmc\RTE' unknown
assembling keil_startup_lpc18xx43xx.s...
compiling fs_mci.c...
Error: C4065E: type of input file 'C:\Users\credo\Downloads\lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\keil\periph_sdmmc\RTE' unknown
compiling rtc.c...
Error: C4065E: type of input file 'C:\Users\credo\Downloads\lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\keil\periph_sdmmc\RTE' unknown
compiling ff.c...
Error: C4065E: type of input file 'C:\Users\credo\Downloads\lpcopen_3_01_keil_iar_nxp_lpcxpresso_1837\LPC43xx_18xx\prj_xpresso1837\keil\periph_sdmmc\RTE' unknown
linking...
.\keil_output\sdmmc.axf: error: L6002U: Could not open file .\keil_output\sysinit.o: No such file or directory

Could you please help me?

0 项奖励
回复

1,749 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

HI Yuanbin Zhou,

   This is the build result on my side, no errors:

pastedImage_1.png

My MDK version is V5.23.

Your result turns out that you are building sdmmc.

Please build the lib at first, take care, the MDK should choose the according lib, then left click, choose the set as active project, then build.

Please build the two lib, and uart project again with my method.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

1,749 次查看
yuanbinzhou
Contributor II

Hi Kerry,

I still cannot compile that project in Keil uVision5. I got the following errors:

Error: C4065E: type of input file 'C:\Users\xxx\Downloads\lpcopen_3_01_keil_iar_ngx_xplorer_1830\LPC43xx_18xx\prj_xplorer1830\keil\periph_uart\RTE' unknown

Please notice that I have build the project lib_lpc_chip_18xx and lib_lpc_board_ngx_xplorer_1830. What should I do?

0 项奖励
回复

1,749 次查看
yuanbinzhou
Contributor II

Hi Kerry Zhou,

Thanks for your reply. Unfortunately in my computer Keil uVision5 or IAR is not available. Could you please provide us with examples with older version of Keil uVision(e.g. Keil uVision4.7). Thanks in advance for your help. 

0 项奖励
回复