Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC24F16ka102 uart not working

Status
Not open for further replies.

Shafaq Gul

Junior Member level 1
Joined
Dec 24, 2013
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
122
Hello!
I am using mplab and proteus...my c code transmits the data but don't receive it.Am really worried.
Code:
#define CRYSTAL_FREQUENCY 10000000      /*  10 MHz  */
#define FCY CRYSTAL_FREQUENCY/2UL       /*  Cylce frequency 5 MHz*/

#include <p24F16KA102.h>
#include <libpic30.h>
#include <stddef.h>


/******************************************************************************/

/*  *** Configuration Bits Setting  *** */

//_FGS(GWRP_OFF & GCP_OFF)
//_FOSCSEL(FNOSC_PRI & IESO_OFF)
//_FOSC(POSCMOD_HS & OSCIOFNC_ON & POSCFREQ_HS & FCKSM_CSDCMD)
//_FWDT(WINDIS_OFF & FWDTEN_OFF)
//_FPOR(BOREN_BOR2 & PWRTEN_OFF  & MCLRE_ON)
//_FDS(DSBOREN_OFF & DSWDTEN_OFF)

_FOSCSEL(FNOSC_FRC);                              // Use internal oscillator  (FOSC ~ 8 Mhz)
_FOSC(FCKSM_CSECMD & OSCIOFNC_ON & POSCMOD_NONE);  // RA3 pin is output    FCKSM_CSECMD         Only clock switching enabled;OSCIOFNC_ON          Digital I/O; POSCMD_NONE          Primary disabled
_FWDT(FWDTEN_OFF);                                // Watchdog timer is disabled
_FICD(BKBUG_OFF); 

/******************************************************************************/
/*
 * 
 */
int i;
unsigned char c;
int main(void)
{
  

      

	U2MODE = 0; // Clear UART1 mode register
	U2STA = 0;	// Clear UART1 status register
    U2MODEbits.BRGH=0;
	U2BRG = 25;

    IPC7bits.U2RXIP = 7;    //set recieve interrupt priority to 4
    IPC7bits.U2TXIP=7;
  
   // IEC1bits.U2RXIE = 1;    //recieve interrupt enable
//    IEC1bits.U2TXIE=1;
 //  _U2RXIF=0;              // Clear UART RX Interrupt Flag
//    _U2TXIF=0;
     
     U2STAbits.URXISEL = 0;  //interrupt when any character is recieved
	U2MODEbits.UARTEN = 1;   // Enable UART2 module
	U2STAbits.UTXEN = 1;     // Enable UART2 transmit 

	
TRISBbits.TRISB1=1;
 
U2STAbits.UTXEN=1;


c='m';
while(U2STAbits.UTXBF);
U2STAbits.UTXBF=1;
U2TXREG=c;

while(!U2STAbits.URXDA);
c=U2RXREG;
U2STAbits.URXDA=1;
while(U2STAbits.UTXBF);
U2STAbits.UTXBF=1;
U2TXREG=c;


while(1);









    return 0;
}
 

The receive code should be inside while(1) loop or in ISR. If ISR is used to receive data then UART Rx interrupt has to be setup.
 

The receive code should be inside while(1) loop or in ISR. If ISR is used to receive data then UART Rx interrupt has to be setup.
Sir...its still not receiving :sad:
 

Can someone check my code.... i tried alot even on another pic but its not working.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top