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

communication between CCS uart and C18 usart

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



Joined: 13 Sep 2012
Posts: 3

View user's profile Send private message

communication between CCS uart and C18 usart
PostPosted: Thu Sep 13, 2012 2:00 pm     Reply with quote

Hi, I have a question. I spend lot of time. There is a receiver circuit and code developed with CCS.
And there is a transmitter circuit and code developed with C18. I want to communicate these circuit serially. I wrote the CCS and C18 code below. Can anyone help me ?

C18 sender code :
Code:

#include<p18f4685.h>
#include <stdlib.h>
#include <string.h>
#include <usart.h>

#pragma config OSC=HSPLL, WDT=OFF, MCLRE=ON, PBADEN=OFF, LVP=OFF

#define LED_TRIS      (TRISAbits.TRISA0)
#define LED_IO         (LATAbits.LATA0)
/*
char SYNC[]={0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x01,0XFE};
char veri[]="Bu bir denemedir.";
char sayi[10];

void dizigonder(char * veri , int uzunluk)
{
    int i;
    for(i=0;i<uzunluk;i++)
    {
        while(BusyUSART());
            putcUSART(veri[i]);
    }
}
*/
void main()
{
    int n=0;
    long int i;
   
    LED_TRIS=0;

    OpenUSART( USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 2082);

    TXSTA = 0x20;
    RCSTA = 0x90;
    BAUDCONbits.BRG16=1;

   
    while(1)
    {
        while(BusyUSART());
            WriteUSART('vexxx\r');
        //putcUSART('veseeds\r\n');
        LED_IO ^= 1;
        Delay10KTCYx(100);
        /*while(BusyUSART());
            WriteUSART('0');
        */
        LED_IO ^= 1;
        Delay10KTCYx(100);
    }
}



CCS receiver code:
Code:

#include <18F4685.h>     // Kullanılacak denetleyicinin başlık dosyası tanıtılıyor.
#fuses HS,NOWDT
#use delay (clock=40000000)
#use rs232 (baud=1200,xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, stop=1)
char kk[20];
void main ( )
{
   while(1)
   {
      gets(kk);
      if(kk[0]=='v' && kk[1]=='e')
      {
         output_high(pin_a0);
         delay_ms(100);
         output_low(pin_a0);
         delay_ms(100);
         printf("ok\r");
      }
   }
   }



Last edited by yalcinelmas on Thu Sep 13, 2012 2:19 pm; edited 2 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Thu Sep 13, 2012 2:15 pm     Reply with quote

Well, you have only posted the CCS code, and called it the C18 code. However comments apply:

1) Your #use RS232 _must_ have 'ERRORS'. This _must_ be present when using the hardware UART, unless you handle hardware errors yourself. Otherwise the UART can become hung.

2) Your C18 code, must terminate what it sends with a line feed.

3) Your C18 code, must pause for at least 0.2 seconds between sending lines.

4) Your transmitted string must be <19 characters long.

5) Your oscillator setup is wrong. HS supports a maximum crystal frequency of 25MHz. Table 27-6, section 1A of the data sheet.

Best Wishes
yalcinelmas



Joined: 13 Sep 2012
Posts: 3

View user's profile Send private message

thanks for answer
PostPosted: Thu Sep 13, 2012 2:24 pm     Reply with quote

I updated my message.

Do you have a comment based on this situation?

Thanks for help ?

By the way I used 25 MHz crystal
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Thu Sep 13, 2012 2:47 pm     Reply with quote

1, 3, & 5 apply. You are sending two characters, receiving all the incoming characters, plus pausing for 200mSec on the CCS PIC. On the C18 end, there are not the extra two characters involved, so it _will_ be looping faster. Your receiving device needs to loop faster than your sending device.

Best Wishes
yalcinelmas



Joined: 13 Sep 2012
Posts: 3

View user's profile Send private message

I could not it :(
PostPosted: Thu Sep 13, 2012 2:58 pm     Reply with quote

I writed below but it is not working... where is incorrect
Code:

  while(BusyUSART());
            WriteUSART('v\r');
        LED_IO ^= 1;
        Delay10KTCYx(200);
        /*while(BusyUSART());
            WriteUSART('0');
        */
        LED_IO ^= 1;
        Delay10KTCYx(200);
ezflyr



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

View user's profile Send private message

PostPosted: Thu Sep 13, 2012 8:35 pm     Reply with quote

Hi,

That's C18 code, and this isn't a C18 forum.

John
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