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 CCS Technical Support

RS232 receive help!

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



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

RS232 receive help!
PostPosted: Thu Nov 29, 2007 3:54 pm     Reply with quote

Hello
I'm desperate. I have worked hours with this simple thing. I cant get the PIC to receive anything from the PC via rs232. I have done this before with exactly the same external hardware with a 16f870 but now I'm using a 18f4550. I se a signal which appers to be good, on my oscilloscope but the receive part does not work thou sending to the PC from PIC works great. All I have done is this
Code:

#use rs232(Baud=19200, Xmit=PIN_C6, Rcv=PIN_C7)

void main()
{
  char c;
  while(1)
  {
    c = getc();
    putc(c);
  }
}

Does anybody know what could be the problem? It all seams very strange to me and I simply can't take this any more..
please help me!
/miniman
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 29, 2007 4:14 pm     Reply with quote

1. Post the #include, #fuses, and #use delay() statement.

2. Post your compiler version.

3. If you're using a factory built board, post the manufacturer and
part number of the board. If you built the board by yourself, then
post a link to a schematic, if possible.
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Fri Nov 30, 2007 1:42 am     Reply with quote

This is my include and delay
Code:

#include <18F4550.h>

#use delay(clock=48M) // 48MHz External Clock

I do not use fuses, the configbits are set once upon programming in the bootloader.
My compilerversion is 4.013.
I'm using a homebuilt board and I don't have any schematic, sorry.
I'm also using decoupling capacitors on both sides of the PIC (two Vdd and two Vss).
Any suggestion what the problem could be?
/miniman
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 30, 2007 2:19 am     Reply with quote

Quote:
I do not use fuses, the config bits are set once upon programming in the
bootloader. My compiler version is 4.013.
I'm using a homebuilt board and I don't have any schematic, sorry.

I don't have 4.013. The closest I have is vs. 4.014. I compiled your
program with that version and compared the .LST file to vs. 4.064.
They're very similar. Vs. 4.604 uses BRGH mode for the Baud Rate
generator. I used the PicBaud baud rate calculator and it says the
SPBRG register value for 19200 baud with a 48 MHz oscillator is 38.
That's the same as 0x26 as shown in the .LST below. See this thread
for a link to the PicBaud utility program:
http://www.ccsinfo.com/forum/viewtopic.php?p=88734

So, assuming that vs. 4.013 produces the same code as 4.014 below,
I don't see a problem with the code. What does that leave ?

1. The bootloader fuses may not be correct for 48 MHz operation.

2. The external crystal frequency may not be correct for the existing
fuses.

3. There may be something wrong with the hardware such as missing
the pull-up resistor on MCLR (assuming that MCLR is enabled).

4. I suspect something is wrong with the serial port connections
which includes the MAX232 chip and the connections to the PC.

Part of the .LST file for vs. 4.014:
Code:
.................... void main() 
.................... { 
0004:  CLRF   FF8
0006:  BCF    FD0.7
0008:  CLRF   FEA
000A:  CLRF   FE9
000C:  BCF    FB8.3

000E:  MOVLW  26
0010:  MOVWF  FAF  // SPBRG

0012:  MOVLW  A2
0014:  MOVWF  FAC  // TXSTA

0016:  MOVLW  90
0018:  MOVWF  FAB  // RCSTA

001A:  MOVF   FC1,W
001C:  ANDLW  C0
001E:  IORLW  0F
0020:  MOVWF  FC1  // ADCON1

0022:  MOVLW  07
0024:  MOVWF  FB4  // CMCON
....................   char c; 
.................... 
....................   while(1) 
....................   { 
....................     c = getc(); 
0026:  BTFSS  F9E.5   // RCIF bit
0028:  BRA    0026
002A:  MOVFF  FAE,06  // RCREG
....................     putc(c); 
002E:  MOVF   06,W
0030:  BTFSS  F9E.4   // TXIF bit
0032:  BRA    0030
0034:  MOVWF  FAD     // TXREG
....................   } 
0036:  BRA    0026
.................... } 
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Sat Dec 01, 2007 3:34 am     Reply with quote

It seams like there is a software problem..
If have tested this code now:
Code:

#INT_RDA
void rda_isr()
{
   putc('R');
   rcvChar = GetC();
   printf("%u",rcvChar);
   putc(' ');
}

With this code I get "R146 R146 R146 ".. printed all over again till i shut the pic down. but if I replace the GetC(); with RCREG; i get 3 chars in the begining when i send my chars out, but not later when i push a key. Do I have to clear the buffer? I thought it would clear itself when I read RCREG, but I also thought that I wouln't need to use registers... Shouldn't Getc() work? I'm getting crazy over this...

I also need help with the configbits, I think the these gonfigbits will work:

But wich fuses to use to get them? I have never used fuses before...

/miniman
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Sat Dec 01, 2007 7:14 am     Reply with quote

I have been able to get it to work a little bit now.. :/
If i use this code, no interrupts:
Code:

   while(1)
   {
      while(!RCIF);
      rcvChar = RCREG;
      printf("-%u-",rcvChar);
      rcvChar = RCREG;
      printf("-%u-",rcvChar);
      rcvChar = RCREG;
      printf("-%u-",rcvChar);

      if(FERR)
         putc('W');
      if(OERR)
      {
         putc('E');
         CREN = 0;
         delay_ms(100);
         CREN = 1;
      }
   }

I then get respons to a key-press. when I press a key I get -97--255--255-E It _ALWAYS_ overrun the buffer, the OERR. And if I in my program only read RCREG and prints it ONCE it does not work att all, then it just prints -255-E every loop without stopping and does not respond to a key strike... Gahh What is happening? Could sombody help me?

/miniman
Ttelmah
Guest







PostPosted: Sat Dec 01, 2007 10:32 am     Reply with quote

What you are describing, is exactly what would happen, if there was a hardware problem, and the receive line into the PIC was held low.
You need to check with a scope, what atually is on the receive input (or even just with a voltmeter, that the line is at 5v, when nothing is being sent...

Best Wishes
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Sat Dec 01, 2007 10:44 am     Reply with quote

I have checked that - It is 5v when nothing is sending.. It all works "fine" when I use the strange code above..
/miniman
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