LPC17xx UART1

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

LPC17xx UART1

跳至解决方案
4,074 次查看
Alex_2221
Contributor IV

Hello, my code works with UART3 and I just want to add UART1 to my code and I use the same piece of code for initializing UART1 that I used for UART3, however I faced this error: #167: argument of type "LPC_UART1_TypeDef *" is incompatible with parameter of type "LPC_UART_TypeDef *". 

I was wondering if you help me resolve this issue. 

Thanks in advance, 

Alex

Here is the part of the code I used:


uartPinSel.Funcnum=PINSEL_FUNC_2;
uartPinSel.OpenDrain=PINSEL_PINMODE_NORMAL;
uartPinSel.Pinmode=PINSEL_PINMODE_TRISTATE;
uartPinSel.Pinnum=0;
uartPinSel.Portnum=0;

PINSEL_ConfigPin(&uartPinSel);
uartPinSel.Pinnum=1;
PINSEL_ConfigPin(&uartPinSel);

uartConfig.Baud_rate=115200;
uartConfig.Databits=UART_DATABIT_8;
uartConfig.Parity=UART_PARITY_NONE;
uartConfig.Stopbits=UART_STOPBIT_1;

UART_Init(LPC_UART3,&uartConfig);
UART_TxCmd(LPC_UART3,ENABLE);

UART_IntConfig(LPC_UART3,UART_INTCFG_RBR,ENABLE);
NVIC_EnableIRQ(UART3_IRQn);



uartPinSel.Funcnum=PINSEL_FUNC_2;
uartPinSel.OpenDrain=PINSEL_PINMODE_NORMAL;
uartPinSel.Pinmode=PINSEL_PINMODE_TRISTATE;
uartPinSel.Pinnum=0;
uartPinSel.Portnum=2;

PINSEL_ConfigPin(&uartPinSel);
uartPinSel.Pinnum=1;
PINSEL_ConfigPin(&uartPinSel);

uartConfig.Baud_rate=38400;
uartConfig.Databits=UART_DATABIT_8;
uartConfig.Parity=UART_PARITY_NONE;
uartConfig.Stopbits=UART_STOPBIT_1;

UART_Init(LPC_UART1,&uartConfig);
UART_TxCmd(LPC_UART1,ENABLE);

标签 (1)
0 项奖励
回复
1 解答
3,990 次查看
aaronminner
Contributor III

Yeah, Alex, it looks like you need a cast to (LPC_UART_TypeDef) on lines 165 and 166:

UART_Init( (LPC_UART_TypeDef *)LPC_UART1,&uartConfig);
UART_TxCmd( (LPC_UART_TypeDef *)LPC_UART1,ENABLE);

For some reason, in whatever version of the tool you're using, uart1 is treated differently than the other uarts.  You can see it here, on line 221 of lpc17xx_uart.c that you included:

 if(((LPC_UART1_TypeDef *)UARTx) == LPC_UART1)

All the other instances of uart default to LPC_UART_TypeDef.  Make those typecasts, above, and it *should* work.  You'll need to typecast LPC_UART1 every time you use it, I'd imagine.

在原帖中查看解决方案

8 回复数
3,991 次查看
aaronminner
Contributor III

Yeah, Alex, it looks like you need a cast to (LPC_UART_TypeDef) on lines 165 and 166:

UART_Init( (LPC_UART_TypeDef *)LPC_UART1,&uartConfig);
UART_TxCmd( (LPC_UART_TypeDef *)LPC_UART1,ENABLE);

For some reason, in whatever version of the tool you're using, uart1 is treated differently than the other uarts.  You can see it here, on line 221 of lpc17xx_uart.c that you included:

 if(((LPC_UART1_TypeDef *)UARTx) == LPC_UART1)

All the other instances of uart default to LPC_UART_TypeDef.  Make those typecasts, above, and it *should* work.  You'll need to typecast LPC_UART1 every time you use it, I'd imagine.

3,981 次查看
Alex_2221
Contributor IV

@aaronminner Yeah, I did that and it worked. Thank you so much

4,010 次查看
frank_m
Senior Contributor III

> error: #167: argument of type "LPC_UART1_TypeDef *" is incompatible with parameter of type "LPC_UART_TypeDef *"

These are different types, it seems. I suppose a type cast should work, but I would check before what the differences are.

4,036 次查看
aaronminner
Contributor III

Two things:

1. LPC_UART1 should translate to a memory address, like this - but different in your case since this is for a FRDM66F and the memory locations are likely not the same:

/** Peripheral UART1 base address */
#define UART1_BASE                               (0x4006B000u)
/** Peripheral UART1 base pointer */
#define UART1                                    ((UART_Type *)UART1_BASE)

Make sure LPC_UART3 and LPC_UART1 resolve to addresses somewhat like that.

2. You should use separate "config" variables for the different peripherals, even if they're of the same UART type.  So create "uartConfig3" and a "uartConfig1" variables and pass those in respectively.  The memory locations are used in the background, and having one variable used for two instances could lead to confusion in data handling.

4,064 次查看
aaronminner
Contributor III

Can you show us the declaration of "uartConfig"? It might be that you just need a typecast for "const uart_config_t *".

4,059 次查看
Alex_2221
Contributor IV

@aaronminner Here uartConfig is declared. Though I uploaded the c file so that you can take a look at the code better if there's something that I'm missing here.

  PINSEL_CFG_Type adcpinsel;

PINSEL_CFG_Type uartPinSel;

UART_CFG_Type uartConfig;

0 项奖励
回复
4,016 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Alex,

do you know  where the structure UART_CFG_Type  is defined? It appears that the UART_CFG_Type structure is not derfined.

Pls have a check

BR

Xiangjun Rong

 

3,995 次查看
Alex_2221
Contributor IV

Hi, I think it's defined in lpc17xx_uart.h driver file. Because when I type F12 it brings me to that file. I added that file here

0 项奖励
回复