CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

pic24FJ128GA010 uart not correct receiving

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alexarndt



Joined: 06 Apr 2010
Posts: 1

View user's profile Send private message

pic24FJ128GA010 uart not correct receiving
PostPosted: Wed Apr 07, 2010 9:16 am     Reply with quote

Hi
I'm trying to send a single character to the microcontroller.
On the one side I use the windows Hyperterminal to send the characters.
On the other side I used the delivered functions from the uart2.h.
I made a loop to check if any data I received.
When this happens I read it to my buffer but I do always receive garbage.
It doesn't matter which char I type. It mostly receives something like 0xF4.
These are the used code fragments:
Code:

//initialize the uart

void UART2Init()
{
    // Set directions of UART IOs
   UART2_TX_TRIS = 0;
   UART2_RX_TRIS = 1;
   U2BRG = BAUDRATEREG2;
   U2MODE = 0;
   U2STA = 0;
   U2MODEbits.UARTEN = 1;
   U2STAbits.UTXEN = 1;
     // reset RX flag
    IFS1bits.U2RXIF = 0;
}

// check for new data
char UART2IsPressed()
{
    if(IFS1bits.U2RXIF == 1)
        return 1;
    return 0;
}

//receive data
char UART2GetChar(){
char Temp;
    while(IFS1bits.U2RXIF == 0);
    Temp = U2RXREG;
    IFS1bits.U2RXIF = 0;
    return Temp;
}

// defines from uart2.h

#define BAUDRATE2      9600

// UART IOs
#ifdef  __PIC24FJ64GA004__
#define UART2_TX_TRIS   PPS_UART2_TX_TRIS
#define UART2_RX_TRIS   PPS_UART2_RX_TRIS
#else
#define UART2_TX_TRIS   TRISFbits.TRISF5
#define UART2_RX_TRIS   TRISFbits.TRISF4
#endif

Thats it. I hope someone could help.
Regards Alex
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Apr 07, 2010 10:02 am     Reply with quote

CCS C has built-in functions for UART handling, that are known to work. Why don't you use it?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group