MK 64 UART0

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MK 64 UART0

839 Views
chaitanyakulkar
Contributor II

Hello ,

I am using MK64 UART0 independently on PORT A 14,15 and PORTB  16,17  By using Pin mux. but i need to use UART0 on PORT B 16,17 and for Some instant we need to switch its PIN mux. on PORT A 14,15. and After that condition we need to re-innitialised to PORT B 16,17.

SO For Same thing i made on function in which 

i) Disable IRQ 31.

ii) Disable Transmission and Reception.

iii) Pin Muxing UART 0 For Particular pin.

iv) Re-Configure interrupt. 

after using this My function well Performing Transition from PORT B to PORT A Switching .but After PORT A 14,15 Transmission and Reception finished we are calling Same function then Switching from PORT A  to PORT B is not going to happen. 

Following Function  I Have Created 

/************************************************************************************************************/

void init_UART0_Printer_DSC_Selection(char DSC_PRINTER_VAL)
{

int CLK_VAL;

disable_irq(31); //FOR UART0 module
SIM_SOPT5 |= SIM_SOPT5_UART0RXSRC(0x00)|SIM_SOPT5_UART0TXSRC(0x00);

core_clk_mhz = EXTRENAL_CRYSTAL_SEL_MHZ; //100;
core_clk_khz = core_clk_mhz * 1000;
periph_clk_khz = core_clk_khz / (((SIM_CLKDIV1 & SIM_CLKDIV1_OUTDIV2_MASK) >> 24)+ 1);
if(DSC_PRINTER_VAL == DSC_SEL_VAL)
{

CLK_VAL = DSC_BAUD;
SIM_SOPT5 |= SIM_SOPT5_UART0RXSRC(0x00)|SIM_SOPT5_UART0TXSRC(0x00);

/************************************************************/
SIM_SCGC4 &= SIM_SCGC4_UART0_UNMASK; //CLOCK For UART0 Get Disable
UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK ); // DisableUART0
UART_C1_REG(UART0_BASE_PTR) = 0x00; /* We need all default settings, so entire register is cleared */
/************************************************************/
PORTB_PCR17 = PORT_PCR_MUX(0x3); //TX //PTB17 DSP_TXD UART0 //VBC 16th Feb. 2017
PORTB_PCR16 = PORT_PCR_MUX(0x3); //RX //PTB16 DSP_RXD UART0 //VBC 16th Feb. 2017
//OLD uart_init (UART0_BASE_PTR, periph_clk_khz, TERMINAL_BAUD); //UART3_BASE_PTR
uart_init (UART0_BASE_PTR, core_clk_khz, DSC_BAUD); //UART3_BASE_PTR - Updated 11-1-19

enable_irq(31); //FOR UART0 module
set_irq_priority(31,7); //Set priority
}
else if(DSC_PRINTER_VAL == PRINTER_SELECTION_VAL )
{
//DSC_SELECTED_OPERATION = 0;
CLK_VAL = TERMINAL_BAUD;
/************************************************************/
SIM_SCGC4 &= SIM_SCGC4_UART0_UNMASK; //CLOCK For UART0 Get Disable
UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK ); // DisableUART0
UART_C1_REG(UART0_BASE_PTR) = 0x00; /* We need all default settings, so entire register is cleared */
/************************************************************/
PORTA_PCR14 = PORT_PCR_MUX(0x3); //TX
PORTA_PCR15 = PORT_PCR_MUX(0x3); //RX

uart_init (UART0_BASE_PTR, core_clk_khz, TERMINAL_BAUD); //UART3_BASE_PTR

enable_irq(31); //FOR UART0 module
set_irq_priority(31,7); //Set priority
}
else
{

CLK_VAL = TERMINAL_BAUD;
SIM_SCGC4 &= SIM_SCGC4_UART0_UNMASK; //CLOCK For UART0 Get Disable
UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK ); // DisableUART0
UART_C1_REG(UART0_BASE_PTR) = 0x00; /* We need all default settings, so entire register is cleared */
/************************************************************/
PORTB_PCR17 = PORT_PCR_MUX(0x3); //TX //PTB17 DSP_TXD UART0 //VBC 16th Feb. 2017
PORTB_PCR16 = PORT_PCR_MUX(0x3); //RX //PTB16 DSP_RXD UART0 //VBC 16th Feb. 2017
//OLD uart_init (UART0_BASE_PTR, periph_clk_khz, TERMINAL_BAUD); //UART3_BASE_PTR
uart_init (UART0_BASE_PTR, core_clk_khz, DSC_BAUD); //UART3_BASE_PTR - Updated 11-1-19


enable_irq(31); //FOR UART3 module
set_irq_priority(31,7); //Set priority

}
/* Enable receiver and transmitter */
UART_C2_REG(UART0_BASE_PTR) |= (UART_C2_TE_MASK | UART_C2_RE_MASK | UART_C2_RIE_MASK| UART_RWFIFO_RXWATER(2));
sysclk_Cal = CLK_VAL; //Init required for UART init while config

}

/************************************************************************************************************/

Note that 

"DSC_PRINTER_VAL " is Use  For UART 0  on PORT B 16 and 17

"PRINTER_SELECTION_VAL " is Use  For UART 0  on PORT A 14 and 15

Please give me solution for same Problem

Tags (1)
2 Replies

708 Views
chaitanyakulkar
Contributor II

Please Send us replay, we need Support ASAP.

0 Kudos

708 Views
mjbcswitzerland
Specialist V

Hi

I think that your solution is far too complicated and is thus the main source of your difficulties.

To change a UART from one pin set to another you just need to do:


1. Disable the receiver

2. Set the original pins to their GPIO function
3. Set the new pins to their UART function
4. Re-enable the receiver

The receiver disable is optional but may stop a spurious character being received during the change.

Regards

Mark

Complete K64 solutions, training and support:http://www.utasker.com/kinetis.html
Kinetis K64:
- http://www.utasker.com/kinetis/FRDM-K64F.html
- http://www.utasker.com/kinetis/TWR-K64F120M.html
- http://www.utasker.com/kinetis/TEENSY_3.5.html
- http://www.utasker.com/kinetis/Hexiwear-K64F.html