Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with MpLab :programming UArt for transmitting data....

Status
Not open for further replies.

fermat7

Member
I have a GPS receiver that transmit data at 4800 bauds....
the task consist of getting the geographical coordinates from the transmitted message:
Code:
$GPGGA,xxxx,xxxxx,xxxxx.......

For that ,i wrote that mplab's code to be implemented on dsPIC30F4011:
Code:
char Rx;
char  Buffer[40];

while(1)
{
if(DataRdyUART1()) 
{ Rx = ReadUART1();
   
    if(Rx == '$')  Buffer[i] = Rx; i++;  
    if(Rx == '\r') {i=0; putsUART1((unsigned int *)Buffer);}
}

}



by that code i expected to get the hole messge on the terminal... but i don't get any thing....


ca someone tell me the problem... especially in the use of the function (putsUARTx)
*the declaration of Buffer ...
*configuration of UARTx register in mplab C30 compiler...!!!


please help as sooon as possible.... thnx
 
here is my complete code
Code:
#include "p30f4011a2.h"                      	// dsPIC30F2010 MPU Register
#include "uart.h"


/* Setup Configuration dspic4011 */
_FOSC(CSW_FSCM_ON & XT_PLL16);							// Enable Clock Switching,Enable Fail-Salf Clock
                                                        // Closk Source = Primary XT + (PLL x 16)
_FWDT(WDT_OFF);											// Disable Watchdog 
_FBORPOR(PBOR_ON & BORV_45 & PWRT_64 & MCLR_EN);		// Enable Brown-Out = 4.5V,Power ON = 64mS,Enable MCLR
_FGS(CODE_PROT_OFF);


unsigned char Rx;
unsigned char Longitude[9];
unsigned char Latitude[9];
unsigned char Buffer[80];



int main(void)
{ 
init_uart1(); // Initialise USART module (8 bit,4800 baud rate, no parity bit..)  

 
  
   i=0;
   k=0;
while(1)
{
	     
        if(DataRdyUART1())
          { 
            Rx = ReadUART1();
	    if(Rx == '$') {k=1;i=0;} // when '$' is detected
	    if( (k==1))   {	 
                        	Buffer[i] = Rx; 
				i++;								
			     }

	   if(Rx == '\r') {
                            i=0;
			    k=0;
//----------- .... Loading Data ... --------------------------
			if((Buffer[4] == 'G')&&(Buffer[5] == 'A'))
		   						 {
            						
			for(mm=0;mm<=8;mm++)   {
                                                              Latitude[mm]=Buffer[mm+18];
								          
							     Longitude[mm]= Buffer[mm+31];
								 
								   }
                 putsUART1((unsigned int*) Latitude);
                 putsUART1((unsigned int*) Longitude);
                 }

   }	
}

for the configuration of the UART:
Code:
void init_uart1(void)
{		  
  CloseUART1();										 		// Disable UART1 Before New Config

  // Config UART Interrupt Control
  ConfigIntUART1(UART_RX_INT_DIS &							// Disable RX Interrupt
    		     UART_RX_INT_PR2 &							// RX Interrupt Priority = 2
    		     UART_TX_INT_DIS &							// Disable TX Interrupt
    		     UART_TX_INT_PR3);							// TX Interrupt Priority = 3  

  // Open UART1 = Mode,Status,Baudrate              
  OpenUART1(UART_EN&	//Enable UART(UART Mode)
                        UART_IDLE_STOP & // Disable UART in IDLE Mode
			UART_RX_TX& 
                        UART_DIS_WAKE &	// Disable Wake-Up
			UART_DIS_LOOPBACK&	// Disable Loop Back
			UART_DIS_ABAUD &		// Disable Auto Baudrate
  			UART_NO_PAR_8BIT& // UART = 8 Bit, No Parity
 			UART_1STOPBIT,	// UART = 1 Stop Bit

	  		// Config UART1 Status
 			UART_INT_TX&         // Select Interrupt After TX Complete
	 		UART_TX_PIN_NORMAL &	//Normal U1TX Mode
 			UART_TX_ENABLE &		// Enable U1TX
 	 		UART_INT_RX_BUF_FUL &	// Flasg Set After RX Complete 
  			UART_ADR_DETECT_DIS &  // Disable Check Address 
			UART_RX_OVERRUN_CLEAR,	// Clear Overrun Flag

  			// DSPIC 30F4011 
  			// XTAL = 10.000 MHz
  			// Fosc = 10.000 MHz x 16 = 160.000 MHz
  			// Fcy(UART) = Fosc / 4 
  			//           = 160.000  / 4 = 40.000 MHz
  			// U1BRG = [Fcy/(16xBaud)]-1
  			//       = [40.000 MHz / (16x4800)] - 1
  			//       = 519 = BFH			
  		       519);											
//----------------------------------------------------------------------------------------




on the terminal console ,i get just the first lecture of latitude ... it doesn't loop !!!
 
Last edited:
.. just a remark... when i change the Latitude array length to 8... it's loops but nothing appears for Longitude!!...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top