I am using MKL17z microcontroller and trying to implement Data transmission uing UART (RS485),but the data register UART2_D is empty

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

I am using MKL17z microcontroller and trying to implement Data transmission uing UART (RS485),but the data register UART2_D is empty

880 Views
priyankavorugan
Contributor II

I have implemented the code as mentioned below.Please let me if i missed any initializations. 

Note: 

I have used the following code.
PTE22 is TX
PTE23 is RX


void uart2_init(void)
{
   SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;
  GPIOE_PDDR |= 0x00400000; //Tx as output and x as input.
  PORTD_PCR22 = PORT_PCR_MUX(0x3u); //chip specific
  PORTD_PCR23 = PORT_PCR_MUX(0x3u);

  UART2_C1 = 0x00; //8bit data,start bit and stop bit ,no parity

  UART2_C2  = 0x00;   Tx off  Rx off


  sbr = ((24*1000000) /(16 * 9600)); BUS clock is 24Mhz ,and baud rate is 9600
  brfa = (((24*1000000*32)/(9600*16)) - ((sbr) * 32));

  UART2_BDH |= 0x00;
  UART2_BDL = ((U8)(sbr));
  UART2_C4 |= ((U8)(brfa));

  (void)UART2_S1; // to clear TX_DATA_REG_EMPTY_FLAG ,TRANSMIT_COMPLETE_FLAG
  (void)UART2_D;

  UART2_C2 = 0x0C; // TX RX On
}

void transmit_data(U8 Buffer_data)
{
while((UART2_S1 & UART_S1_TDRE_MASK)==0);     // Wait for transmit buffer to be empty 
(void)UART2_S1;                                                             // Read UART2_S1 register to clear TDRE 
UART2_D=Buffer_data;                                                 // Send data
}


void main(void)
{
    while(TRUE)
   {
       transmit_data(0x01);
   }
}

Labels (1)
0 Kudos
2 Replies

744 Views
priyankavorugan
Contributor II

Hi xiangjun.rong ,

After posting the issue i noticed that it should be ALT4 and not ALT3.So i changed that configurations and my UART is working properly. 

Thankyou.

0 Kudos

744 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

pastedImage_1.png

I suppose you should use the foolwoing code:

SIM_SCGC5|=0x2000; //set PORTE clock

  PORTE_PCR22 = PORT_PCR_MUX(0x4u); //It is PORTE instead of PORTD and ALT4 instead of ALT3
  PORTE_PCR23 = PORT_PCR_MUX(0x4u);

   SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;

Pls use the above setting and have a try.

BR

XiangJun Rong

0 Kudos