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 problem, char routing through PIC

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



Joined: 12 Jul 2007
Posts: 32

View user's profile Send private message

RS232 problem, char routing through PIC
PostPosted: Tue Oct 28, 2008 7:04 am     Reply with quote

Hi,
I have a problem with RS232 and character routing through a PIC.
But now from beginning:
I use a bluetooth and a GSM module. For each I have a PIC. From my "main board" I send a character to the bluetooth/GSM PIC (via hardware rs232) and then via software rs232 to the according module. Following I send it back to my Computer via bluetooth or GSM. The problem is that I don't get the right characters, only each second (e.g. send: thisisatest; get: tiiaet).
Why?

For sending and receiving I use fputc and fgetc in a loop.
Do you need any further information?
Thanks.

P.s.: The help says something like "send it 10 times". But what does it mean? (Sorry, I have no help available now).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 12:05 pm     Reply with quote

Post the sending and receiving programs. Make them be very short,
like 10 lines in each program. Cut out all unnecessary lines of code,
The programs should have a #include, #fuses, #use delay, #use rs232,
and a main(). They must be compilable. Test the programs, verify
that they show the error, and then post them. They must be short.
Also post your compiler version.
spom



Joined: 12 Jul 2007
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 4:14 am     Reply with quote

Below the code for the PIC on the GSM/bluetooth modul board:
Code:
#include <18f1320.h>
#fuses NOWDT,HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,INTRC
#use delay(internal=8M)
#use rs232(baud=2400,xmit=PIN_B3,rcv=PIN_B2,BRGH1OK,ERRORS,stream=TB)
#use rs232(baud=2400,xmit=PIN_B1,rcv=PIN_B4,BRGH1OK,stream=GSM)
void main() {
while(kbhit(TB)){
c = fgetc(TB);
fputc(GSM,c);
}
}

The characters I send via Docklight, a HyperTerminal programm. TB is a hardware UART and GSM is the software UART.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 6:25 am     Reply with quote

Quote:

Code:
#include <18f1320.h>
#fuses NOWDT,HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,INTRC
#use delay(internal=8M)
#use rs232(baud=2400,xmit=PIN_B3,rcv=PIN_B2,BRGH1OK,ERRORS,stream=TB)
#use rs232(baud=2400,xmit=PIN_B1,rcv=PIN_B4,BRGH1OK,stream=GSM)
void main()
{
  while(kbhit(TB))
  {
      c = fgetc(TB);
      fputc(GSM,c);
  }
}

I have reformatted your code so that you can more easily see what is wrong. The "while(kbhit(TB))" loop is only satisfied as long as there is a character waiting to be read. After one character is handled, the code drops out of the loop and then clean off the end of the main() program. From there it somehow finds its way back to the beginning of the program where it re-initializes everything. In the meantime you have missed an incoming character, which is why you get every other character. I think what you really wanted was:

Code:

void main()
{
  while(1)
  {
     if(kbhit(TB))
     {
        c = fgetc(TB);
        fputc(GSM,c);
     }
  }
}


_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
spom



Joined: 12 Jul 2007
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 7:35 am     Reply with quote

Thanks.
I tried it that way but I still have the same problem. I also tried to change baud rate but with no effect. I tried to use a buffer - no effect.
I think the problem is in the software UART....
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 10:20 am     Reply with quote

For the SW #use RS232, add FORCE_SW to it. It should be able to figure it out, just in case it didn't though, add it in there. Also, are you sure that it's not a HW problem? If possible, write a small program to send out via RS-232 a count. Then connect it to a terminal program and make sure that both sides can send out to the terminal correctly. I suggest you do only one at a time. Just to rule out an HW problem, and that the UART's SW+HW are working.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
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