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

Problem with 18f44k22's dual uart

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



Joined: 04 May 2013
Posts: 4

View user's profile Send private message

Problem with 18f44k22's dual uart
PostPosted: Sat May 04, 2013 3:07 am     Reply with quote

I am now using 18f44k22 with two pairs of UART where the first pair is to connect to xbee and the 2nd pair is for gsm. But i encounter problem when i use the two pairs of uart together. The PIC work well when i use only one pair of it for gsm, the sms received is as expected, the header declaration is:

Code:
#use rs232(UART2,baud=9600, parity=N,bits=8, xmit=PIN_D6, rcv=PIN_D7, errors, stream=GSM)

but when i add in the declaration of 2nd pair of uart:(only the header, i haven't even add in the coding for the xbee part)


Code:
#use rs232(UART1,baud=9600, parity=N,bits=8, xmit=PIN_C6, rcv=PIN_C7, errors, stream=XBEE)
#use rs232(UART2,baud=9600, parity=N,bits=8, xmit=PIN_D6, rcv=PIN_D7, errors, stream=GSM)


I have problem with the sms received, the sms can only be sent out when ON the circuit for twice. and the sms received will be overlapped, meaning that, the content in a single sms is double of the message that should be received.. any idea what cause this to be happened? thanks.


Last edited by pingice on Sat May 04, 2013 9:12 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Sat May 04, 2013 3:29 am     Reply with quote

You _are_ hopefully using fgetc, fputc, and kbhit(stream)?.
Once two UART's are declared, you need to be using these throughout. Otherwise how can the compiler know which port to use?.

Best Wishes
pingice



Joined: 04 May 2013
Posts: 4

View user's profile Send private message

PostPosted: Sat May 04, 2013 3:54 am     Reply with quote

Thanks for the reply.. Smile
Yes, i include fgetc, fputc, and kbhit(stream) in my coding. What do you mean by "how can the compiler know which port to use"? I tried the coding that include the xbee part (not only header) too, the same thing happend. Once I used 2nd pairs of the uart, the sms received will be overlapped and only sent out on the 2nd time. what will be the possible causes?
The coding:
Code:
# Include <18f44k22.h>
# Use delay (clock = 1000000)
#fuses NOLVP,NOWDT,NOPROTECT,NOBROWNOUT, NOWRT
#use rs232(UART1,baud=9600, parity=N,bits=8, xmit=PIN_C6, rcv=PIN_C7, force_sw, errors, stream=XBEE)
#use rs232(UART2,baud=9600, parity=N,bits=8, xmit=PIN_D6, rcv=PIN_D7, force_sw, errors, stream=GSM)
#include <stdlib.h>

char a;
int e =1;
int p =0;
int o=0;

void send_num1()
{
   fprintf(GSM, "at+cmgs=\"xxxxxxxxxxx\"\r\n");
   delay_ms(500);
}       
       

void main ()
{
fprintf(GSM, "ate0\r\n");         
delay_ms(2000);
fprintf(GSM, "at+cmgf=1\r\n");
delay_ms(2000);

while (true)
{

   if ((INPUT (PIN_A2)==0))
   {
   if (p==0)
   {
   send_num1();
   fprintf(GSM,"Pole ID:0003\r\nPower Down\r\nLocation: xxxx");
   putc(26);
   delay_ms(1000);
   p=1;//
   }
   }
   
 {
if (kbhit(XBEE))
{     
         a = getc(XBEE);
           
       if (a=='A')
       {
       if (e==0)
         {
          send_num1();
          fprintf(GSM,"Pole ID:0001\n\fPower Down \n\fLocation: xxxx");
          putc(26);
         e=1;
         }
       }
}
}
}
}


Last edited by pingice on Sat May 04, 2013 9:11 am; edited 1 time in total
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat May 04, 2013 6:05 am     Reply with quote

Hi,

There are a number of issues with the code you posted, at least one of which might explain the problem you are reporting.

Here are some suggestions:

1. Move your #use delay statement after your #fuses statement. This is the correct order.

2. Remove the 'force_sw' directive from your #use rs232 statements. Why in the world you added that code between your 1st and 2nd posts is totally beyond me. Why did you do that?

3. Substitute 'fputc' for 'putc' in you code. You stated that you had used streams with all serial functions, but this is not true!

4. Your 'send_num()' routine is weird. You should have a 'Send_SMS()' routine instead that sends the whole message instead of breaking it up like you do now. The only thing that changes in this routine will be the actual text that is being sent. You can pass the text to your subroutine, or you can set a 'MsgID' variable, and use Switch to select the proper message to send, like this:

Code:

switch (MsgID)
   {
      Case 0:   //Send AC Power Restored Msg!
            fprintf(ADH8066, "AC Power Restored ");
            break;


5. Use the 'Code' buttons when posting your code!

John
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat May 04, 2013 8:42 am     Reply with quote

Also, you don't need the UARTx designations and the pin numbers in
the USE_RS232 statement, one or the other but not both.

Code:
#use rs232(UART1,baud=9600, parity=N,bits=8, errors, stream=XBEE)
#use rs232(UART2,baud=9600, parity=N,bits=8, errors, stream=GSM)

Should be all you need.
_________________
Google and Forum Search are some of your best tools!!!!
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