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

getc reads only trash

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



Joined: 09 May 2007
Posts: 6

View user's profile Send private message

getc reads only trash
PostPosted: Wed Apr 30, 2008 2:42 am     Reply with quote

Hi,

I'am trying to get a char over the rs232 interrupt INT_RDA of my pic. But what ever I sent to the controller by HyperTerminal, it gets only a 0xFF.

I'am using a PIC18F2480 and a CCS PCWH Compiler in the version 4.062.

I've done a small project, to show the problem more detailled.

Can anybody help my.

Thanks a lot.

Regards Tomson



Code:
#include   "18F2480.h"


#fuses   HS, PROTECT
#fuses   BROWNOUT
#fuses   WDT128, BORV42
#fuses   PUT, NOCPD, STVREN, NODEBUG
#fuses   NOLVP, NOWRT, NOWRTD, NOIESO, FCMEN
#fuses   NOPBADEN, BBSIZ1K, NOWRTC, NOWRTB, NOEBTR
#fuses   NOEBTRB, CPB, NOLPT1OSC, MCLR
#fuses   NOXINST
     
#use   delay(clock=12000000, RESTART_WDT)

#use    fast_io(A)
#use    fast_io(B)
#use    fast_io(C)

#use    RS232(baud=2400, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=E, RESTART_WDT)


   //***********************************************************************************
   //** global variables
   //***********************************************************************************
   char   dummy;

   //***********************************************************************************
   //** interrupt service routine
   //***********************************************************************************
   #int_rda
   void rx_isr()
   {   
      dummy = getc();    // the result of the getc command is always 0xFF!
   }

   //***********************************************************************************
   //** main program
   //***********************************************************************************
   void main(void)
   {

      #zero_ram




      //***********************************************************************************
      //** Set Port C directions
      //***********************************************************************************
          SET_TRIS_C(0b10010010); 

      //***********************************************************************************
      //** Start WatchDog
      //***********************************************************************************
        SETUP_WDT(WDT_ON);
   
      //***********************************************************************************
      //** Enable interrupts
      //***********************************************************************************
      enable_interrupts(INT_RDA);
        enable_interrupts(GLOBAL);
   
      
      //***********************************************************************************
      //** Send a test message
      //***********************************************************************************
      printf("\n\n\r Test program"); // This works fine!


      //***********************************************************************************
      //** Start main loop
      //***********************************************************************************
      do
      {

         if (dummy != 0)
         {
            putc(dummy);
            dummy = 0;
         }


         //***********************************************************************************
         //** restart WatchDog
         //***********************************************************************************
         RESTART_WDT();
      

      } while(True);         
   
   }
Matro
Guest







PostPosted: Wed Apr 30, 2008 2:50 am     Reply with quote

Check carefully that the PC has exactly the same settings as the PIC.

how is done the level shifting between PC and PIC?

Matro
Tomson



Joined: 09 May 2007
Posts: 6

View user's profile Send private message

PostPosted: Wed Apr 30, 2008 2:56 am     Reply with quote

Hi Matro,

thank you for your fast reply. The hyperterminal and the pic has the same RS232 settings. 2400, 8E1. The communication from PIC to PC works fine. I sent a short message at the start of the program that is received well by HyperTerminal.

Level shifting is done with a MAX232 derivate that works fine in other projects.

Tomson
Matro
Guest







PostPosted: Wed Apr 30, 2008 3:13 am     Reply with quote

Could you try the posted code but without :
- the 3 "#use fast_io" lines
- the "set_tris_c" line

Did you already have a look at the incoming signals with a scope?

Matro
Tomson



Joined: 09 May 2007
Posts: 6

View user's profile Send private message

PostPosted: Wed Apr 30, 2008 3:33 am     Reply with quote

There is no change in the behavior after I've outposted the suggested lines.
I've looked at the incoming signal with the scope and recognized that this was very strange. I've to look more detailled for it.

Thank you very much.

Regards Tomson
Matro
Guest







PostPosted: Wed Apr 30, 2008 3:44 am     Reply with quote

I definitely suspect a hardware issue.

Matro
Tomson



Joined: 09 May 2007
Posts: 6

View user's profile Send private message

PostPosted: Wed Apr 30, 2008 3:47 am     Reply with quote

Hi Matro,

at the moment I think the same. I will do some tests on the board.
Thank you very much for your help.

Regards, Tomson
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Apr 30, 2008 11:57 am     Reply with quote

char dummy is not initialized. Look at setting a global flag in the RDA isr to indicate a char has been read. Initialize the global flag and clear it main after you have processed the value in dummy. It is very likely that the issue lies with your receive hardware but tightening up the software might help also.
baltazar_aquino



Joined: 16 Mar 2008
Posts: 27

View user's profile Send private message

PostPosted: Fri May 02, 2008 10:03 pm     Reply with quote

This is really more likely a hardware problem. I've experienced the same issue and later on found out the following:
1: Wrong connection of TX-RX (reversed) pins between the D9 connector & the MAX 232 chip.
2. I used a transistor level converter instead of a dedicated chip . Sometimes this type of converter cannot drive the D9 port properly to acceptable RS-232 mark and space levels. (This is especially true if you are using a USB-RS232 converter- as in a laptop).
Kindly refer to this topic.
http://www.ccsinfo.com/forum/viewtopic.php?t=34110&highlight=
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