UART on KL25Z don't working

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

UART on KL25Z don't working

Jump to solution
1,613 Views
wojciech22a
Contributor II

I wrote a short program whose aim is to send the character 'g' through UART and blinking LED. Unfortunately but the program is not working. I use KDS 3.0 and KL25Z. Configuration: 8 bits data, none parity, one bit stop.  I using OpenSDA Virtual Serial COM -pins PTA1 and PTA2. Please help.

#include "MKL25Z4.h"

static int i = 0;

void opz(int ile)

{

  int p;

  for(p=0;p<ile;p++)

  {

  }

}

void ledkonf(void)

{

  SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;

  PORTB_PCR19=PORTB_PCR19 &~(1<<10) &~(1<<9) | (1<<8);

  GPIOB_PDDR=GPIOB_PDDR | (1<<19);

}

void uartkonf(void)

{

  SIM_SCGC4=SIM_SCGC4| (1<<10);//enable uart0

  SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;//enable PORTA

  PORTA_PCR1=PORTA_PCR1 &~(1<<10) | (1<<9) &~(1<<8);//010mask -uart

  PORTA_PCR2=PORTA_PCR2 &~(1<<10) | (1<<9) &~(1<<8);

  UART0_BDH=0x02;//9600 baud; OSR = 3; module clock 20.97152MHz SBR=546 = 1000100010

  UART0_BDL=0x22;

  UART0_C1 = 0x00;

  UART0_C2 = 0x00;

  UART0_C2=UART0_C2 | (1<<3);//TE bit on

  //UART0_S1=0xC0;

  UART0_C3 = 0x00;

  UART0_C4=0x03;//OSR-3

  UART0_C5=0x02;

}

void swiec(void)

{

   opz(100000);

   GPIOB_PDOR=GPIOB_PDOR|(1<<19);

   opz(100000);

   GPIOB_PTOR=GPIOB_PTOR|(1<<19);

   opz(100000);

}

void Transmisja( unsigned char data )//transmit function

{

while ( !( UART0_S1 & (1<<7)));

UART0_D = data;

}

unsigned char Odbior( void )

{

while ( !(UART0_S1 & (1<<5)) );

return UART0_D;

}

int main(void)

{

    /* Write your code here */

    /* This for loop should be replaced. By default this loop allows a single stepping. */

  ledkonf();

  uartkonf();

    for (;;) {

    unsigned char Kp='g';

    Transmisja(Kp);

       swiec();

    }

    /* Never leave main */

    return 0;

}

////////////////////////////////////////////////////////////////////////////////

// EOF

////////////////////////////////////////////////////////////////////////////////

Labels (1)
0 Kudos
1 Solution
957 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi wojciech22a,

      You didn't choose the clock source for UART0 module, please add this :

  SIM_SOPT2 |= SIM_SOPT2_UART0SRC(1);

  in your void uartkonf(void), it choose MCGFLLCLK clock as the uart0 clock, if you don't choose it, the clock will be disabled in default, that is why you can't send the data with UART0.

  I use your code, after I add this, the code is working.

  Attached is my test project, you can refer to it:

  Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
958 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi wojciech22a,

      You didn't choose the clock source for UART0 module, please add this :

  SIM_SOPT2 |= SIM_SOPT2_UART0SRC(1);

  in your void uartkonf(void), it choose MCGFLLCLK clock as the uart0 clock, if you don't choose it, the clock will be disabled in default, that is why you can't send the data with UART0.

  I use your code, after I add this, the code is working.

  Attached is my test project, you can refer to it:

  Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
957 Views
mjbcswitzerland
Specialist V

Hi

I don't see any obvious error but it would be useful to known what is in fact not working.

Is the UART not sending anything? Is it sending at the wrong Baud rate?

Is it not working because something else is not working? - eg. the code crashes before trying to send or gets stuck in a forever loop? Are the LEDs blinking as you expect?

Regards

Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support  / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos