[SOLVED] Problem,RTC value send in to UART3 in lpc 1768

Status
Not open for further replies.

arunbharathi.arasu

Full Member level 2
Joined
Feb 28, 2013
Messages
134
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,298
Location
Chennai, Tamil Nadu, India
Visit site
Activity points
2,151
hi,
i have problem to send RTC value in to UART3 inLPC1768,
i can send welcome message in to UART3,but i can't read and send RTC value to UART3.
i don't know where the problem is.

can any one help me.....

Thanks in Advance...
 

the below code is Real Time Clock with UART3 in lpc 1768.
Required:In Terminal after welcome message if i press any key RTC time will display.
I got welcome message correctly but if i press any key i get number of dots.
Code:
/*
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif
#include "type.h"
#include "uart.h"
#include <string.h>
#include "rtc.h"



volatile uint32_t UART3Status;
volatile uint8_t  UART3TxEmpty=1;
volatile uint8_t  UART3Buffer[BUFSIZE];
volatile uint32_t UART3Count = 0;



extern volatile uint32_t alarm_on;
RTCTime local_time, alarm_time, current_time;


void UART3_IRQHandler (void)
{
  uint8_t IIRValue, LSRValue;
  uint8_t Dummy = Dummy;

  IIRValue = LPC_UART3->IIR;

  IIRValue >>= 1;			/* skip pending bit in IIR */
  IIRValue &= 0x07;			/* check bit 1~3, interrupt identification */
  if ( IIRValue == IIR_RLS )		/* Receive Line Status */
  {
	LSRValue = LPC_UART3->LSR;
	/* Receive Line Status */
	if ( LSRValue & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
	{
	  /* There are errors or break interrupt */
	  /* Read LSR will clear the interrupt */
	  UART3Status = LSRValue;
	  Dummy = LPC_UART3->RBR;		/* Dummy read on RX to clear
							interrupt, then bail out */
	  return;
	}
	if ( LSRValue & LSR_RDR )	/* Receive Data Ready */
	{
	  /* If no error on RLS, normal ready, save into the data buffer. */
	  /* Note: read RBR will clear the interrupt */
	 UART3Buffer[UART3Count] = LPC_UART3->RBR;
	  UART3Count++;
	  if ( UART3Count == BUFSIZE )
	  {
		UART3Count = 0;		/* buffer overflow */
	  }
	}
  }
  else if ( IIRValue == IIR_RDA )	/* Receive Data Available */
  {
	/* Receive Data Available */
	UART3Buffer[UART3Count] = LPC_UART3->RBR;
	UART3Count++;
	if ( UART3Count == BUFSIZE )
	{
	  UART3Count = 0;		/* buffer overflow */
	}
  }
  else if ( IIRValue == IIR_CTI )	/* Character timeout indicator */
  {
	/* Character Time-out indicator */
	UART3Status |= 0x100;		/* Bit 9 as the CTI error */
  }
  else if ( IIRValue == IIR_THRE )	/* THRE, transmit holding register empty */
  {
	/* THRE interrupt */
	LSRValue = LPC_UART3->LSR;		/* Check status in the LSR to see if
									valid data in U0THR or not */
	if ( LSRValue & LSR_THRE )
	{
	  UART3TxEmpty = 1;
	}
	else
	{
	  UART3TxEmpty = 0;
	}
  }
}

uint32_t UARTInit(uint32_t baudrate )
{
  uint32_t Fdiv;
  uint32_t pclkdiv, pclk;
	  LPC_PINCON->PINSEL0 &= ~0x0000000F;
	  LPC_PINCON->PINSEL0 |=  0x0000000A;  /* RxD3 is P0.1 and TxD3 is P0.0 */
	  LPC_SC->PCONP |= 1<<4 | 1<<25; //Enable PCUART1
	  /* By default, the PCLKSELx value is zero, thus, the PCLK for
		all the peripherals is 1/4 of the SystemFrequency. */
	  /* Bit 6~7 is for UART3 */
	  pclkdiv = (LPC_SC->PCLKSEL1 >> 18) & 0x03;
	  switch ( pclkdiv )
	  {
	  case 0x00:
	  default:
		  pclk = SystemCoreClock/4;
		  break;
	  case 0x01:
		  pclk = SystemCoreClock;
		  break;
	  case 0x02:
		  pclk = SystemCoreClock/2;
		  break;
	  case 0x03:
		  pclk = SystemCoreClock/8;
		  break;
	  }
	  LPC_UART3->LCR = 0x83;		/* 8 bits, no Parity, 1 Stop bit */
	  Fdiv = ( pclk / 16 ) / baudrate ;	/*baud rate */
	  LPC_UART3->DLM = Fdiv / 256;
	  LPC_UART3->DLL = Fdiv % 256;
	  LPC_UART3->LCR = 0x03;		/* DLAB = 0 */
	  LPC_UART3->FCR = 0x07;		/* Enable and reset TX and RX FIFO. */

	  NVIC_EnableIRQ(UART3_IRQn);

	  LPC_UART3->IER = IER_RBR | IER_THRE | IER_RLS;	/* Enable UART3 interrupt */
	return (TRUE);
}

void UARTSend(uint8_t *BufferPtr)
{
  while ( *BufferPtr )
    {
	  /* THRE status, contain valid data */
	  while ( !(UART3TxEmpty & 0x01) );
	  LPC_UART3->THR = *BufferPtr;
	  UART3TxEmpty = 0;	/* not empty in the THR until it shifts out */
	  BufferPtr++;
	}
}
void RTCInit( void )
{

  /* Enable CLOCK into RTC */
  LPC_SC->PCONP |= (1 << 9);

  /* If RTC is stopped, clear STOP bit. */
  if ( LPC_RTC->RTC_AUX & (0x1<<4) )
  {
	LPC_RTC->RTC_AUX |= (0x1<<4);
  }

  /*--- Initialize registers ---*/
  LPC_RTC->AMR = 0;
  LPC_RTC->CIIR = 0;
  LPC_RTC->CCR = 0;
  return;
}

void RTCStart( void )
{
  /*--- Start RTC counters ---*/
  LPC_RTC->CCR |= CCR_CLKEN;
  LPC_RTC->ILR = ILR_RTCCIF;
  return;
}
void RTCSetTime( RTCTime Time )
{
  LPC_RTC->SEC = Time.RTC_Sec;
  LPC_RTC->MIN = Time.RTC_Min;
  LPC_RTC->HOUR = Time.RTC_Hour;
  LPC_RTC->DOM = Time.RTC_Mday;
  LPC_RTC->DOW = Time.RTC_Wday;
  LPC_RTC->DOY = Time.RTC_Yday;
  LPC_RTC->MONTH = Time.RTC_Mon;
  LPC_RTC->YEAR = Time.RTC_Year;
  return;
}

RTCTime RTCGetTime( void )
{
  RTCTime LocalTime;

  LocalTime.RTC_Sec = LPC_RTC->SEC;
  LocalTime.RTC_Min = LPC_RTC->MIN;
  LocalTime.RTC_Hour = LPC_RTC->HOUR;
  LocalTime.RTC_Mday = LPC_RTC->DOM;
  LocalTime.RTC_Wday = LPC_RTC->DOW;
  LocalTime.RTC_Yday = LPC_RTC->DOY;
  LocalTime.RTC_Mon = LPC_RTC->MONTH;
  LocalTime.RTC_Year = LPC_RTC->YEAR;
  return ( LocalTime );
}

int main(void)
{
	const char* msg = "                   HH: MM: SS:   DD: MM: YY:\r";
		const char* welcomeMsg = "Real time clock is:";
		const char* space = "  ";
		const char ascii[] ={'0','1','2','3','4','5','6','7','8','9'};

		UARTInit(9600);	/* baud rate setting */
		UARTSend((uint8_t*)msg);
		UARTSend((uint8_t *)welcomeMsg);

		RTCInit();

			  local_time.RTC_Sec = 0;
			  local_time.RTC_Min = 0;
			  local_time.RTC_Hour = 0;
			  local_time.RTC_Mday = 11;
			  local_time.RTC_Wday = 5;
			  local_time.RTC_Yday = 11;		/* current date 07/12/2006 */
			  local_time.RTC_Mon = 10;
			  local_time.RTC_Year = 2013;
			  RTCSetTime( local_time );		/* Set local time */
			  RTCStart();

			  while(1)
			  {
			  	current_time = RTCGetTime();

				if ( UART3Count != 0 )
				{

					UARTSend((uint8_t *)ascii[current_time.RTC_Hour/10]);
					UARTSend((uint8_t *)ascii[current_time.RTC_Hour%10]);
					UARTSend((uint8_t *)space);
					UARTSend((uint8_t *)ascii[current_time.RTC_Min/10]);
					UARTSend((uint8_t *)ascii[current_time.RTC_Min%10]);
					UARTSend((uint8_t *)space);
					UARTSend((uint8_t *)ascii[current_time.RTC_Sec/10]);
					UARTSend((uint8_t *)ascii[current_time.RTC_Sec%10]);
					UARTSend((uint8_t *)space);
					UARTSend((uint8_t *)space);
					UARTSend((uint8_t *)ascii[current_time.RTC_Mday/10]);
					UARTSend((uint8_t *)ascii[current_time.RTC_Mday%10]);
					UARTSend((uint8_t *)space);
					UARTSend((uint8_t *)ascii[current_time.RTC_Mon/10]);
					UARTSend((uint8_t *)ascii[current_time.RTC_Mon%10]);
					UARTSend((uint8_t *)space);
					UARTSend((uint8_t *)ascii[current_time.RTC_Year/1000]);
					UARTSend((uint8_t *)ascii[(current_time.RTC_Year%1000)/100]);
					UARTSend((uint8_t *)ascii[(current_time.RTC_Year%10)/10]);
					UARTSend((uint8_t *)ascii[current_time.RTC_Year%10]);
					}
				UART3Count = 0;
			  }
}
 

Hi take care on ISR receiver condition read all the data in the buffer when interrupt coming and why do you pressing any chars is your RTC working fine??
 

I think these should be global as they are constants and they are stored in ROM during compilation.


Code C - [expand]
1
2
3
const char* welcomeMsg = "Real time clock is:";
const char* space = "  ";
const char ascii[] ={'0','1','2','3','4','5','6','7','8','9'};



I don't know if LPC allows to write to ROM during program run.
 

hi venkadesh,
Key pressing is just for an Interrupt.After welcome message,if interrupt occurs RTC will display.But i get get special characters and dots.I dont know where the problem is.
above i posted my code can you help me....

- - - Updated - - -

hi jayanth,
That is not a global constant.It is local constant only(i declered inside the main function).
 

you cant do such like when programing but you can set correct time by giving user input when run time like correcting the time in watch...
 

I didn't say it is a global constant. Some compilers like mikroe compilers doesn't allow to define const strings inside functions. They should be declared as global. I don't use LPC. Maybe your compiler allows.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…