kinteis k10 uart program error

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

kinteis k10 uart program error

747 Views
gnsh2196
Contributor II

I am working on a custom board with k10mcu mk10dx256. IM trying to implement uart program with it.I have attached the program.I am getting a garbage value on my serial terminal.

heres my program:

#include <__cross_studio_io.h>
#include "MK10DZ10.h"

main(){
char data = 'a';
int i;
unsigned long int SBR_value=0;
char data1,ch;

//pin selection
SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;
PORTD_PCR3 |= PORT_PCR_MUX(3);
PORTD_PCR2 |= PORT_PCR_MUX(3);
//uart selection
SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;
UART2_C2 |= (1<<3)|(1<<2);

SBR_value = (int) ( (72*1000000)/ ( 16 * 9600) ) ;
UART2_BDH |= ( ( SBR_value >> 8 ) & 0x1F );
UART2_BDL = ( SBR_value & 0xFF );

while(1)
{

while( !(( UART2_S1 >> 7) & 0x01));
ch|= data;
UART2_D |=ch;
debug_printf("sending\n %s \n %d \n ",data,i#);}

}Untitled.png

i m getting interrupts but my data is not able to captured in receive program.

Labels (1)
Tags (2)
0 Kudos
4 Replies

640 Views
gnsh2196
Contributor II



// MCG_C1 Reg Config

MCG_C1 &= ( MCG_C1_CLKS(0x00) | MCG_C1_FRDIV(0x00) );
MCG_C1 |= ( MCG_C1_IREFS_MASK | MCG_C1_IRCLKEN_MASK );

// MCG_C2 Reg Config
MCG_C2 = 0x00; // Disable all the functionalities

//SYSTEM_FREQUENCY
// MCG_C4 Reg Config selecting the range to 60 - 72Mhz
MCG_C4 |= (MCG_C4_SCFTRIM_MASK | MCG_C4_DMX32_MASK );
MCG_C4 |= ( 1 << ( MCG_C4_DRST_DRS_SHIFT + 1) ) ;


//---------- SIM Module

SIM_SOPT2 &= ~(SIM_SOPT2_PLLFLLSEL_MASK); // Selecting the FLL
// common for 72Mhz 
SIM_CLKDIV1 |= ((SIM_CLKDIV1_OUTDIV4(0x02)) | (SIM_CLKDIV1_OUTDIV3(0x01)) | (SIM_CLKDIV1_OUTDIV2(0x01)) | (SIM_CLKDIV1_OUTDIV1(0x00) ) );

this is my clock configuration

for 72mhz.

Untitleda.png

this is my output after  configuring the clock.

0 Kudos

640 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

can you use a oscilloscope to check the baudrate?

Regards,

Jing

0 Kudos

640 Views
gnsh2196
Contributor II

hi,

thanks  for your help i have figured it out. there seems to be change in the baud rate calculation.

current baudrate  was set as 19200.

thank you

0 Kudos

640 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi ganesh,

I think this may the baudrate problem. First, please clarify what kind of K10 are you using. You use K10DZ10.h. This is form 100Mhz main clock device. But in your code, you use 72M to calculate SBR. Second, after reset, the chip clock is in FEI mode. FLL output 20.97M clock to system. You should initialize the clock first.

Regards,

Jing