AnsweredAssumed Answered

UART on KL25Z don't working

Question asked by wojciech22a on Jul 30, 2015
Latest reply on Jul 30, 2015 by Kerry Zhou

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

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

Outcomes