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

RS485 between two PIC problem!
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
musti463



Joined: 19 Sep 2013
Posts: 66

View user's profile Send private message

PostPosted: Wed Aug 27, 2014 5:52 am     Reply with quote

I have new question. Why we will coupling DE and RE pins. If we tie this pins,so why manufacturers produces this pins?
_________________
M.Emir SADE
temtronic



Joined: 01 Jul 2010
Posts: 6808
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Aug 27, 2014 6:49 am     Reply with quote

By having individual control of both transmitter and receiver sections of the device,a designer can optimize his code that controls the RS-485 databus.

Similar to why cars have both gas and brake pedals. Technically NOT required but the driver has more 'options' on how to control the car.

hth
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 20759

View user's profile Send private message

PostPosted: Wed Aug 27, 2014 1:57 pm     Reply with quote

If you connect RE and DE together, the transceiver chip is either sending
or receiving (half duplex) and it only takes 1 pin on your PIC to control
the send/receive mode.

If RE and DE are separately controlled by two pins on your PIC, you
could enable both at the same time, and then transmit a byte and
receive it back in your PIC, to test if the circuit is working OK.
Also, if you don't receive the same message that you sent, it could mean
that another device is trying to send at the same time. (This is called
a collision). So you could abort sending for a short time, and then try again.
musti463



Joined: 19 Sep 2013
Posts: 66

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 7:11 am     Reply with quote

Hello again me, again problem Smile

I am sending data from master to slave. So sometimes slave get message instantly. But sometimes delay and get message.

What is the reason for this delay and instability?
_________________
M.Emir SADE
ezflyr



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

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 7:27 am     Reply with quote

Hi,

Do you have any real hardware, or is this just a pure simulation? If it's a Proteus simulation, we don't want to waste anymore time on it. If it's real hardware, please post a picture of the hardware, and show us your latest code.

John
musti463



Joined: 19 Sep 2013
Posts: 66

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 9:24 am     Reply with quote

I record video about my problem:

http://youtu.be/g6cMNWmP760


And so i cant understand, my circuit work correctly this video:

http://youtu.be/x7cwHIuxYow

Master Code:

Code:
#INCLUDE <16f877.h> 
#FUSES XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#USE delay (clock=4000000)
#USE rs232(baud=250000,xmit=pin_c6,rcv=pin_c7,enable=pin_c5,bits=9,errors,stream=PIC)
#DEFINE use_portb_lcd TRUE
#INCLUDE <lcd.c>
#INCLUDE <input.c>
#INCLUDE <stdlib.h>
#DEFINE RS485_ID  0x07
#DEFINE RS485_DEST_ID  0x03
#INCLUDE <rs485.c>

int data,i;
int *pointer=&data; 

void main ( )
{
   setup_psp(PSP_DISABLED);     
   setup_spi(SPI_SS_DISABLED);   
   setup_timer_1(T1_DISABLED);   
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);             
   setup_CCP1(CCP_OFF);           
   setup_CCP2(CCP_OFF);

   set_tris_b(0x00);
   set_tris_c(0x80);
   set_tris_d(0x00);
   output_b(0x00);
   output_d(0x00);
   
   output_high(pin_c5);
   
   rs485_init();
   delay_ms(50);
   lcd_init();
   delay_ms(50);
   
   while(1)
   {
      printf(lcd_putc,"\f");
      i=0;
      data=0;
      for(i;i<100;i++)
      {
     
      if(rs485_send_message(RS485_DEST_ID,1,&data))
        {
         printf(lcd_putc,"\fGonderildi%u",i);
         delay_ms(500);
        }
       
        data++;
      }
     
   }
}



Slave Code:

Code:
#INCLUDE <16f877.h> 
#FUSES XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#USE delay (clock=4000000)
#USE rs232(baud=250000,xmit=pin_c6,rcv=pin_c7,enable=pin_c5,bits=9,errors,stream=PIC)
#DEFINE use_portb_lcd TRUE
#INCLUDE <lcd.c>
#INCLUDE <input.c>
#INCLUDE <stdlib.h>
#DEFINE RS485_ID  0x03
#INCLUDE <rs485.c>

int data[3];
int *pointer=&data[0];

void main()
{

   setup_psp(PSP_DISABLED);        // PSP birimi devre dışı
   setup_spi(SPI_SS_DISABLED);     // SPI birimi devre dışı
   setup_timer_1(T1_DISABLED);     // T1 zamanlayıcısı devre dışı
   setup_timer_2(T2_DISABLED,0,1); // T2 zamanlayıcısı devre dışı
   setup_adc_ports(NO_ANALOGS);    // ANALOG giriş yok
   setup_adc(ADC_OFF);             // ADC birimi devre dışı
   setup_CCP1(CCP_OFF);            // CCP1 birimi devre dışı
   setup_CCP2(CCP_OFF);            // CCP2 birimi devre dışı

   set_tris_b(0x00);
   set_tris_c(0x80);
   output_b(0x00);
   
   output_low(pin_c5);
   
   rs485_init();
   delay_ms(50);
   lcd_init();
   delay_ms(50);

   printf(lcd_putc,"\fBilgi: ");

   while (1)
      {
            rs485_get_message(pointer,false);
            delay_ms(50);
            printf(lcd_putc,"\fBilgi:%u",pointer[2]);
           
      }
}


Circuit:


_________________
M.Emir SADE
ezflyr



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

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 10:00 am     Reply with quote

Hi,

I think your problem description is faulty? It seems that in the 'non-working' example, the Slave is missing some transmissions from the Master, it's not a matter of 'delay'.....

What is the difference between your working code, and your non-working code?

BTW, your hardware looks good! Congratulations on taking this project into the 'real world'!!

John
musti463



Joined: 19 Sep 2013
Posts: 66

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 10:03 am     Reply with quote

ezflyr wrote:
Hi,

I think your problem description is faulty? It seems that in the 'non-working' example, the Slave is missing some transmissions from the Master, it's not a matter of 'delay'.....

What is the difference between your working code, and your non-working code?

BTW, your hardware looks good! Congratulations on taking this project into the 'real world'!!

John


@ezflyr same codes. There is one code (sometimes working sometimes non-working code) Smile

I couldn't understand
_________________
M.Emir SADE
SherpaDoug



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

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 10:30 am     Reply with quote

Is it an actual delay or is the problem that most messages are being lost? It looks to me like when a new message is received it is only one number behind what is sent.
_________________
The search for better is endless. Instead simply find very good and get the job done.
musti463



Joined: 19 Sep 2013
Posts: 66

View user's profile Send private message

PostPosted: Sat Sep 06, 2014 1:46 am     Reply with quote

I am still have this problem !
_________________
M.Emir SADE
musti463



Joined: 19 Sep 2013
Posts: 66

View user's profile Send private message

PostPosted: Mon Sep 08, 2014 7:13 am     Reply with quote

I did this code for RS485 wishing and sender protocol. Can you tell me your ideas?

Wisher:

Code:
  char gelen_bilgiX[9]={};
  char *gelen_bilgi=&gelen_bilgiX[0];
  int emir=1;
 
  output_high(pin_c5);
 
  for(int i=0;i<=5;i++)
  {
   if(rs485_send_message(RS485_ID_1,1,&emir))
   {
      output_low(pin_c5);
      rs485_get_message(gelen_bilgi,false);
      break;
   }
  }


Sender:

Code:
char giden_bilgiX[9]={};
char *giden_bilgi=&giden_bilgiX[0];
int komut_s[1]={0};
int *komut=&komut_s[0];
float voltaj;

output_low(pin_c5);

while(true)
  {
     
      if(komut==0)
      {
         rs485_get_message(komut,false);
      }
     
      else if(komut==1)
      { 
         set_adc_channel(0);
         delay_us(20);
         bilgi=read_adc();
         voltaj=0.0048828125*bilgi;   
     
         sprintf(giden_bilgiX,"%f",voltaj);//float to string işlemi gerçekleştiriliyor
         
         output_high(pin_c5);   
         rs485_send_message(RS485_MASTER_ID,8,giden_bilgi);
         
      }
  }

_________________
M.Emir SADE
ezflyr



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

View user's profile Send private message

PostPosted: Mon Sep 08, 2014 9:21 am     Reply with quote

Hi,

Creating two threads for basically the same project/problem is very confusing. I though your problems were solved in the other thread? Do you have a new problem? If so, please explain what that problem is. We should not have to guess!!

without trying to analyze your code, one thing that you are doing stands out as very wrong. You should not be directly manipulating 'Pin_C5'. This is the 'enable' pin for your RS485 transceivers, and will be controlled automatically by the compiler as long as you are using the 'Enable' directive in your #use_rs232 declaration.

John
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
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