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

Problem with RS485....

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



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

Problem with RS485....
PostPosted: Thu Mar 18, 2010 5:50 am     Reply with quote

Hello CCS Friends,

I try to sending data in between the two PIC micro-controller using RS485. I using Inbuilt driver RS485.c to write the programs for master and salve micro-controller. i use the ISIS software to test the circuit.. but program is not working.. kindly check my program, what mistake i done in program...


Master PIC IC Program
Quote:

#include <16F877A.h>
#device *=16
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PC)

#include <string.h>

#define RS485_DEST_ID 0x11 //Destination's ID

#define RS485_ID 0x7F
#define RS485_USE_EXT_INT TRUE
#include <rs485.c>

void main()
{
int8 i, msg[32];

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(GLOBAL);
rs485_init();
Fprintf(PC,"Master Ready\r\n");
While(True)
{

Output_high(pin_D7);
Delay_ms(500);
Output_low(pin_D7);
Delay_ms(500);
strcpy(msg,"A");


rs485_wait_for_bus(False);
i=1;
while(!rs485_send_message(RS485_DEST_ID, i, msg))
{
delay_ms(RS485_ID);
}
} // While Close
}



Salve PIC IC Program..
Quote:

#include <16F877A.h>
#device *=16
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PC)

#define RS485_ID 0x11
#define RS485_USE_EXT_INT TRUE
#include <rs485.c>

void main()
{
int8 i, msg[32];
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

enable_interrupts(GLOBAL);
rs485_init();


Fprintf(PC,"Salve-01 Ready\r\n");

While(True)
{
if(rs485_get_message(msg, FALSE)) {
for(i=0; i<msg[1]; ++i)
fputc(msg[i+2], PC);
}
} // While Close
}



ISIS Circuit
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 7:13 am     Reply with quote

Nobody respond this thread because it does not have an easy/short answer.
Looking at your code and schematic is easy to see some 'beginner mistakes' -do not offend-
Search in this forum you will find very good discusions to read and learn regarding RS485.
Let me suggest you to read them, and if you need further help, ask an specific problem,
not in the way: "why does not function my whole project ".

Regards,

Humberto
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Mar 19, 2010 6:58 am     Reply with quote

It would also help if you could tell as specifically as possible what it does or doesn't do. For example: Does the transmitter send anything? Does the receiver receive anything? Does it receive the wrong thing? Is the first character right? Examples of what you tried to send and what was received, preferably both in hex would help.
_________________
The search for better is endless. Instead simply find very good and get the job done.
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Sat Mar 20, 2010 4:21 am     Reply with quote

The #use RS232 directive does not contain the enable option, this is essential to enable and disable transmission and reception of data.

Is the RS485.c file same as the one in the PICC folder ??

thanks
arunb
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

Re: RE:
PostPosted: Sun Mar 21, 2010 12:02 am     Reply with quote

arunb wrote:
The #use RS232 directive does not contain the enable option, this is essential to enable and disable transmission and reception of data.

Is the RS485.c file same as the one in the PICC folder ??

thanks
arunb

Hi Arun,

I use inbuilt driver(RS485.C) for RS485. I don't understand your point. I connect circuit as per driver file of RS485.C.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 8:46 am     Reply with quote

The point is, in your code there is not any code to handle the enable Rx/Tx pins
of the SN75176 transciever. Remember that a with single loop in RS485, you are able to
run in Half Duplex Mode only, that is:
If you activate the transmit enable pin, you can transmit but as soon as you end the transmition,
you must disable it in order to release the line and set the transceiver for Rx listening, that
is the state to receive data in the loop.

A workaround regarding this is to wire both control pins (2 and 3) to an output PIC
pin and use the option ENABLE in the #use RS232 directive to tell the compiler that
you are using an RS485 transceiver, then let the compiler to generate the appropiate
code to handle the communication direction control.

http://www.ccsinfo.com/forum/viewtopic.php?t=33778
http://www.ccsinfo.com/forum/viewtopic.php?t=39115
http://www.ccsinfo.com/forum/viewtopic.php?t=33914


Regards,

Humberto
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