![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
yalcinelmas
Joined: 13 Sep 2012 Posts: 3
|
communication between CCS uart and C18 usart |
Posted: Thu Sep 13, 2012 2:00 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Thu Sep 13, 2012 2:15 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
yalcinelmas
Joined: 13 Sep 2012 Posts: 3
|
thanks for answer |
Posted: Thu Sep 13, 2012 2:24 pm |
|
|
I updated my message.
Do you have a comment based on this situation?
Thanks for help ?
By the way I used 25 MHz crystal |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Thu Sep 13, 2012 2:47 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
yalcinelmas
Joined: 13 Sep 2012 Posts: 3
|
I could not it :( |
Posted: Thu Sep 13, 2012 2:58 pm |
|
|
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);
|
|
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Sep 13, 2012 8:35 pm |
|
|
Hi,
That's C18 code, and this isn't a C18 forum.
John |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|