uart examples ?

Başlatan armsistem, 03 Kasım 2011, 00:41:48

armsistem

Arkadaşlar selam,aşağıdaki code parçası pll ayarlıyorum problem yok ama çalıştırdığım zaman saçmalıyor ,düzeltmek için startup.s dosyasına giriyorum peripheral clock selection register0 (pclksel0) - PCLK_UART0  ----> Pclk=Cclk/4 yerine 2 yapıyorum düzeliyor ,bunun sebebi nedir.

Şimdiden teşekkürler.

/*****************************************************************************
 *   target.h:  Header file for NXP LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.09.20  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#ifndef __TARGET_H 
#define __TARGET_H

#ifdef __cplusplus
   extern "C" {
#endif

/* Only choose one of them below, by default, it's Keil MCB2300 */
#define ENG_BOARD_LPC24XX				0
#define KEIL_BOARD_LPC23XX				1
#define EA_BOARD_LPC24XX				0
#define IAR_BOARD_LPC23XX				0

/* On EA and IAR boards, they use Micrel PHY.
   on ENG and KEIL boards, they use National PHY */
#define NATIONAL_PHY			1
#define MICREL_PHY				2

/* If USB device is used, CCO will be 288Mhz( divided by 6) or 384Mhz( divided by 8)
to get precise USB clock 48Mhz. If USB is not used, you set any clock you want
but make sure the divider of the CCO should be an even number. If you want to 
use USB, change "define USE_USB" from 0 to 1 */
 
#define	USE_USB					1


/* PLL Setting Table Matrix */
/* 	
	Main Osc.	CCLKCFG		Fcco		Fcclk 		M 	N
	12Mhz		29		300Mhz		10Mhz			24	1
	12Mhz		35		360Mhz		10Mhz			14	0					
	12Mhz		27		336Mhz		12Mhz			13	0		
	12Mhz		17		360Mhz		20Mhz			14	0
	12Mhz		13		336Mhz		24Mhz			13	0
	12Mhz		11		300Mhz		25Mhz			24	1   
	12Mhz		9		300Mhz		30Mhz			24	1
	12Mhz		11		360Mhz		30Mhz			14	0
	12Mhz		9		320Mhz		32Mhz			39	2
	12Mhz		9		350Mhz		35Mhz			174	11
	12Mhz		7		312Mhz		39Mhz			12	0 
	12Mhz		7		360Mhz		45Mhz			14	0  
	12Mhz		5		300Mhz		50Mhz			24	1
	12Mhz		5		312Mhz		52Mhz			12	0
	12Mhz		5		336Mhz		56Mhz			13	0				
	12Mhz		3		300Mhz		75Mhz			24	1
	12Mhz		3		312Mhz		78Mhz			12	0  
	12Mhz		3		320Mhz		80Mhz			39	2
	12Mhz		3		336Mhz		84Mhz			13	0 
*/

/* These are limited number of Fcco configuration for
USB communication as the CPU clock and USB clock shares
the same PLL. The USB clock needs to be multiple of
48Mhz. */
#if USE_USB		/* 1 is USB, 0 is non-USB related */  
/* Fcck = 48Mhz, Fosc = 288Mhz, and USB 48Mhz */
#define PLL_MValue			11
#define PLL_NValue			0
#define CCLKDivValue		5
#define USBCLKDivValue		5

/* System configuration: Fosc, Fcclk, Fcco, Fpclk must be defined */
/* PLL input Crystal frequence range 4KHz~20MHz. */
#define Fosc	12000000
/* System frequence,should be less than 80MHz. */
#define Fcclk	48000000
#define Fcco	288000000
#else

/* Fcck = 60Mhz, Fosc = 360Mhz, USB can't be divided into 48Mhz
in this case, so USBCLKDivValue is not needed. */
#define PLL_MValue			14
#define PLL_NValue			0
#define CCLKDivValue		5

/* System configuration: Fosc, Fcclk, Fcco, Fpclk must be defined */
/* PLL input Crystal frequence range 4KHz~20MHz. */
#define Fosc	12000000
/* System frequence,should be less than 72MHz. */
#define Fcclk	60000000
#define Fcco	360000000

#endif

/* APB clock frequence , must be 1/2/4 multiples of ( Fcclk/4 ). */
/* If USB is enabled, the minimum APB must be greater than 16Mhz */ 
#if USE_USB
#define Fpclk	(Fcclk / 2)
#else
#define Fpclk	(Fcclk / 4)
#endif

/******************************************************************************
** Function name:		TargetInit
**
** Descriptions:		Initialize the target board; it is called in a 
**				necessary place, change it as needed
**
** parameters:			None
** Returned value:		None
**
******************************************************************************/
extern void TargetInit(void);
extern void ConfigurePLL( void );
extern void TargetResetInit(void);

#ifdef __cplusplus
   }
#endif
 
#endif /* end __TARGET_H */
/******************************************************************************
**                            End Of File
******************************************************************************/

yamak

Saçmalıyor derken neyi kastetdiniz? Eğer saçma karakterler okuyosanız baudrate ayarında sorun vardır.Mesela UART ın çalışmaz pclk/4 iken 25 mhz dir pclk/2 iken 50 mhz ve baudrate hesabı 50 mhz e göre yapılmışsa baudrate uyuşmazlığından böyle bi sorun çıkar ortaya.

armsistem

#2
NXP'nin sitesinden 'LPC2000 UART Baudrate Calculator' excel formül dosyasını indirdim.Uart,baudrate değerlerimi girdiğimde aşağıdaki sonuçları çıkarıyor , fakat girdiğimde 115200 ile düzgün haberleştiremiyorum değişik karakterler çıkıyor . Bir şeyi gözden kaçırdım ama bulamadım , tıkandım  ; yardımcı olan arkadaşlara için şimdiden teşekkür ederim.


LPC2000 UART Baudrate Calculator         
         
Please enter the following two parameters:         
UART clock [Hz]         57600000
Requested  UART baudrate      115200
Maximum allowed relative error [%]   2,5
         
Best available fit for standard UART         
UART baudrate         116129,03
Relative error         0,81%
UDL [dec]         31
UDLM [dec]         0
UDLL [dec]         31
         
Best available fit for enhanced UART         
UART baudrate         115200,00
Relative error         0,00%
UDL [dec]                         25
UDLM [dec]         0
UDLL [dec]         25
DivAddVal [dec]         1
MulVal [dec]         4
         
Terms of Use: http://www.nxp.com/terms         






düzgün çalışmayan
{
U0FCR = 0x07;  /* 8 bits, Parity yok, 1 Stop bit*/
U0LCR = 0x83;  /*OK*/
U0DLL = 0x18;  /*U0DLL = 0x3A;*/
U0DLM = 0x00;
U0LCR = 0x04;
}





hata olabilir olan bölüm;
PLLCON &= ~0x01; // Disable the PLL
PLL_Feed();
CLKSRCSEL = 0x01; // PLL clock source is main oscillator (Fin = 16 MHz)
PLLCFG = 0x8; // M=9, N=1 (2 x M x Fin) / N = Fcco = 288 MHz
PLL_Feed();
PLLCON = 0x01; // Enable the PLL
PLL_Feed();
CCLKCFG = 0x03; // CPU clock is 288 MHz / 4 = 72 MHz
USBCLKCFG = 0x05; // USB clock is 288 MHz / 6 = 48 MHz
PCLKSEL0 = 0x000000C0; // PCLK_UART0 is CCLK/8 clock



Kodun tamamı ;
#include "LPC23xx.h"


int putchar(int ch);
int getchar(void);
int i;


void PLL_Feed(void)
{
PLLFEED = 0xAA;
PLLFEED = 0x55;
}

void InitFrequency(void)
{
if((PLLSTAT & 0x02000000) != 0 ) // If PLL is already connected, disconnect the PLL
{
PLLCON &= ~0x02;
PLL_Feed();
}

PLLCON &= ~0x01; // Disable the PLL
PLL_Feed();
CLKSRCSEL = 0x01; // PLL clock source is main oscillator (Fin = 16 MHz)
PLLCFG = 0x8; // M=9, N=1 (2 x M x Fin) / N = Fcco = 288 MHz
PLL_Feed();
PLLCON = 0x01; // Enable the PLL
PLL_Feed();
CCLKCFG = 0x03; // CPU clock is 288 MHz / 4 = 72 MHz
USBCLKCFG = 0x05; // USB clock is 288 MHz / 6 = 48 MHz
PCLKSEL0 = 0x000000C0; // PCLK_UART0 is CCLK/8 clock

while(!(PLLSTAT & 0x04000000)); // Wait for the PLL lock

PLLCON |= 0x03; // Connect the PLL
PLL_Feed();
}

void InitGPIO(void)
{
PINSEL0 = 0x00000050;
}

int putchar(int ch)  /* Write character to Serial Port */
  {if (ch == '\n')
     {while (!(U0LSR & 0x20));
      U0THR = 0x0D; /* output CR */
     }
   while (!(U0LSR & 0x20));
      return (U0THR = ch);
  }
int getchar (void) /* Read character from Serial Port */
  {while (!(U0LSR & 0x01));
     return (U0RBR);
  }


void InitUART0(void)
{
U0FCR = 0x07;  /* 8 bits, Parity yok, 1 Stop bit*/
U0LCR = 0x83;  /*OK*/
U0DLL = 0x18;  /*U0DLL = 0x3A;*/
U0DLM = 0x00;
U0LCR = 0x04;
}

void Delay(unsigned int time)
{
while(time--);
}

int main(void)
{
InitFrequency();
InitGPIO();
InitUART0();

while(1)
{
putchar(getchar());
IOCLR1 = 0x0600;
Delay(50000);
IOSET1 = 0x0600;
Delay(50000);
}
}