LPC17xx UART1

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
2,872件の閲覧回数
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 解決策
2,788件の閲覧回数
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 返答(返信)
2,789件の閲覧回数
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.

2,779件の閲覧回数
Alex_2221
Contributor IV

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

2,808件の閲覧回数
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.

2,834件の閲覧回数
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.

2,862件の閲覧回数
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 *".

2,857件の閲覧回数
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 件の賞賛
2,814件の閲覧回数
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

 

2,793件の閲覧回数
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 件の賞賛