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

Receiver problem in RS 485 communication

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



Joined: 28 Jul 2009
Posts: 13

View user's profile Send private message

Receiver problem in RS 485 communication
PostPosted: Wed Aug 26, 2009 10:29 pm     Reply with quote

Code for transmitter:
Code:

/// code for the master PIC or the node A

#include <16F887.h>
#fuses HS, NOWDT, NOLVP, NOPROTECT
#use delay(clock=20000000)

 #define RS485_RX_PIN       PIN_C7   // Data receive pin
  #define RS485_TX_PIN       PIN_C6   // Data transmit pin
  #define RS485_ENABLE_PIN   PIN_B4   // Controls DE pin.  RX low, TX high.
  #define RS485_RX_ENABLE    PIN_B5
 
  #use rs232(baud=9600, xmit=RS485_TX_PIN , rcv=RS485_RX_PIN , enable=RS485_ENABLE_PIN)

#include <rs485.c>             //rs485 c driver file is called here
//#include <flex_lcd.c>
int8 msg;
char* p;
int8 size=20;
void main()
{    int j;
  // int data_received[32];
   //lcd_init();
   //output_low(LCD_RW);
   rs485_init();
msg=0x01;

p=&msg;
   while(1)
   {
      rs485_wait_for_bus(FALSE);
                   //send address=0x11, length = 1, msg=3
   if(rs485_send_message(0x01, 1, p))
      {
              //lcd_gotoxy(1,3);
         //printf(lcd_putc, "\n sent..\n");
         delay_ms(100);
      }
      delay_ms(5);
   }
}


For receiver:
Code:

/// code for the slave PIC or the node B

#include <16F887.h>

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT
#use delay(clock=20000000)

#define SLAVE_ID 0x10    //slave ID defined
#include <flex_lcd.c>


 #define RS485_RX_PIN       PIN_C7   // Data receive pin
  #define RS485_TX_PIN       PIN_C6   // Data transmit pin
  #define RS485_ENABLE_PIN   PIN_B4   // Controls DE pin.  RX low, TX high.
  #define RS485_RX_ENABLE    PIN_B5
  #include <rs485.c>             //rs485 c driver file is called here
#include <stdlib.h>
 #use rs232(baud=9600, xmit=RS485_TX_PIN , rcv=RS485_RX_PIN , enable=RS485_RX_ENABLE)
int8 i;
 int8 data[32];
void main()
{
rs485_init();
lcd_init();
output_low(LCD_RW);
         lcd_putc('\f');
            printf(lcd_putc, "initd");delay_ms(500);lcd_putc('\f');
         while(1){
             printf(lcd_putc, "WL");
              delay_ms(200);
               //lcd_putc('\f');

      if(rs485_get_message(data, FALSE))   //does not enter this loop
       {printf(lcd_putc, "a=%d ", data[0]);
       delay_ms(300);
       lcd_gotoxy(1,1);
        printf(lcd_putc, "dl=%d ", data[1]);   
        delay_ms(300);
       lcd_gotoxy(1,1);
        printf(lcd_putc, "d=%d ", data[2]);
            delay_ms(300);
           //lcd_putc('\f');}
         
         }
         }
}

I have observed the working in the scope. The transmitter works fine.
The scope says that the data is coming up to the Rx pin of the receiver PIC but is not read.
Is there any problem with the code??
I have tried to work out with interrupts but that doesn't work either.
Could anybody tell me where I am making mistake.
shashank27187



Joined: 28 Jul 2009
Posts: 13

View user's profile Send private message

PostPosted: Wed Aug 26, 2009 10:40 pm     Reply with quote

The problem I have is similar to the one posted in the topic
http://www.ccsinfo.com/forum/viewtopic.php?t=39964
arloedx



Joined: 21 Aug 2009
Posts: 15
Location: Texas

View user's profile Send private message

PostPosted: Fri Aug 28, 2009 8:49 am     Reply with quote

Hi,

You are having a similar problem to what I am having. I was unable to get the rs485_get_message to work properly, but I was able to receive the data I was transmitting using this:

Code:

#include <18f252.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use    delay(clock=10000000)
#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7, stream=PC)
     .
     .
     .
     .
int8 in_char = 0;
int8 next_in = 0;
int8 next_out = 0;
int8 msg[64];

char PCgetc()
{
   in_char = 0;

   while(!in_char);

   return in_char;
}

typedef struct
{
   int8 from_id;
   int8 to_id;
   int8 length;
   int8 data1;
   int8 data2;
}receive_buffer;

void main()
{
   receive_buffer rb;
     .
     .
     .
   rb.from_id = PCgetc();
   rb.to_id = PCgetc();
   if(rb.to_id == RS485_ID)
   {
      rb.length = PCgetc();
      rb.data1 = PCgetc();
      rb.data2 = PCgetc();
      printf(lcd_putc, "%c", rb.data1);
         }
     .
     .
     .
}


Let me know if you come up with a new solution.
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