AnsweredAssumed Answered

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

Question asked by priyanka v on Sep 21, 2016
Latest reply on Sep 25, 2016 by priyanka v

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);
   }
}

Outcomes