Microcontroller - NXP Kinetis MKE14F512VLL16
IDE - MCUXpresso v11.3.0
SDK - SDK_2.x_MKE14F512XXX16 ,v2.8.8
Hello,
I've an application in which I have to use the same LPUART module in two different ports. Different peripheral is connected to each port and I don't want to use them simultaneously.
Peripheral 1(P1) is connected to:
PTA3 (ALT6)- LPUART0-TX
PTA2 (ALT6)- LPUART0-RX
Peripheral 2(P2) is connected to:
PTB0 (ALT2)- LPUART0-RX
PTB1 (ALT2)- LPUART0-TX
In my application, I'm initializing the LPUART0 module with Port A2 and A3 using the following code.
void InitLPUART0(void){
PCC->CLKCFG[PCC_LPUART0_INDEX] |= PCC_CLKCFG_PCS(3); //System Oscillator Bus Clock
PCC->CLKCFG[PCC_LPUART0_INDEX] |= PCC_CLKCFG_CGC(1); //PCC Configuration - Enable Clock
PORTA->PCR[2] |= PORT_PCR_MUX(6); /* LPUART - ALT6 */
PORTA->PCR[3] |= PORT_PCR_MUX(6);
LPUART0->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK);
LPUART0->BAUD = BAUD_115200; //48M/(26*16)Baud rate for 115200bps
LPUART0->CTRL |= LPUART_CTRL_RIE(1); /* Receiver Interrupt Enable */
LPUART0->CTRL |= LPUART_CTRL_TE(1); /* Transmitter enable */
LPUART0->CTRL |= LPUART_CTRL_RE(1); /* Receiver Enable */
NVIC_EnableIRQ(LPUART0_RX_IRQn);
}
Initially ,this is working as expected. The system is sending data as expected through the port.
When I need to use the other peripheral, I'm shifting the LPUART0 to the other port as shown below.
LPUART0->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK); /* Disable Tranceiver */
PORTA->PCR[3] |= PORT_PCR_MUX(1); /* LPUART - ALT1 - GPIO */
PORTA->PCR[2] |= PORT_PCR_MUX(1);
PORTB->PCR[0] |= PORT_PCR_MUX(2); /* LPUART - ALT2 - UART */
PORTB->PCR[1] |= PORT_PCR_MUX(2);
LPUART0->CTRL |= (LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK); /* Enable Tranceiver */
After shifting the system is supposed to send the data through the Port B to peripheral 2. But the LPUART lines are idle even though the transmission code is running. After switching ports, if I switch back to peripheral 1 in Port A using the same method, it doesn't respond either.
The system is working if use either of the ports without switching to the another.
What is wrong in this method?
解決済! 解決策の投稿を見る。
Hello all,
Just found out the solution. I was overwriting bits 8, 9 and 10 corresponding to the MUX settings in the PORTx_PCR register instead of clearing them.
Corrected method is posted below.
void SelectCOMPort(COMPORT_TYPE CPort){ /* Directs LPUART0 to the required port and disables others */
LPUART0->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK); /* Disable Tranceiver */
switch (CPort)
{
case PORT_1:
PORTB->PCR[0] &= ~(BIT8 | BIT9 | BIT10); /* LPUART - Disable */
PORTB->PCR[1] &= ~(BIT8 | BIT9 | BIT10);
PORTA->PCR[3] |= PORT_PCR_MUX(6); /* LPUART - ALT6 - to UART */
PORTA->PCR[2] |= PORT_PCR_MUX(6);
break;
case PORT_2:
PORTA->PCR[3] &= ~(BIT8 | BIT9 | BIT10); /* LPUART - Disable */
PORTA->PCR[2] &= ~(BIT8 | BIT9 | BIT10);
PORTB->PCR[0] |= PORT_PCR_MUX(2); /* LPUART - ALT2 - to UART */
PORTB->PCR[1] |= PORT_PCR_MUX(2);
break;
default:
break;
}
LPUART0->CTRL |= (LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK); /* Enable Tranceiver */
}
Hello all,
Just found out the solution. I was overwriting bits 8, 9 and 10 corresponding to the MUX settings in the PORTx_PCR register instead of clearing them.
Corrected method is posted below.
void SelectCOMPort(COMPORT_TYPE CPort){ /* Directs LPUART0 to the required port and disables others */
LPUART0->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK); /* Disable Tranceiver */
switch (CPort)
{
case PORT_1:
PORTB->PCR[0] &= ~(BIT8 | BIT9 | BIT10); /* LPUART - Disable */
PORTB->PCR[1] &= ~(BIT8 | BIT9 | BIT10);
PORTA->PCR[3] |= PORT_PCR_MUX(6); /* LPUART - ALT6 - to UART */
PORTA->PCR[2] |= PORT_PCR_MUX(6);
break;
case PORT_2:
PORTA->PCR[3] &= ~(BIT8 | BIT9 | BIT10); /* LPUART - Disable */
PORTA->PCR[2] &= ~(BIT8 | BIT9 | BIT10);
PORTB->PCR[0] |= PORT_PCR_MUX(2); /* LPUART - ALT2 - to UART */
PORTB->PCR[1] |= PORT_PCR_MUX(2);
break;
default:
break;
}
LPUART0->CTRL |= (LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK); /* Enable Tranceiver */
}