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

[Help] RS485 PIC to PIC

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



Joined: 16 Aug 2013
Posts: 1

View user's profile Send private message

[Help] RS485 PIC to PIC
PostPosted: Fri Aug 16, 2013 11:57 am     Reply with quote

Hi for all,
I need transmit the number 1 for the slave but the program dont work...

Here are my master code:

Code:
#include <18F452.h>

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

#define RS485_RX_BUFFER_SIZE 32

#define RS485_ID             0x01
#define RS485_DEST_ID        0x09

#include <rs485.c>
#include <stdlib.h>

int i, max = 1 ;

int8 bufsend[1] = {1};
int8 size=sizeof(bufsend);

int *pointer;

void main()
{
     
    rs485_init();
   
   while(true)
      {
     
      for(i=0; i<max; i++)
      {
         pointer = &bufsend[i];
         
               rs485_send_message(0x09, size, pointer);//send for outer pic       
         
          delay_ms(100);
      }
      delay_ms(300); 
   }
}


And my slave:

Code:
#include <18F452.h>

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

#define RS485_RX_BUFFER_SIZE 32

#define  RS485_ID             0x09

#include <rs485.c>
#include <flex_lcd.c>

int i;

int8 msg[32];

void main()
{
   
   output_low(RS485_ENABLE_PIN); 
   rs485_init();
   rs485_no=1;
   lcd_init();

   printf(lcd_putc,"test");
   delay_ms(500);
   while(true)   
   {
     
     
    if (rs485_get_message (msg, FALSE)) {
       //printf (lcd_putc, "% d", msg [1]);
       for(i=0;i<10;i++){
       if(msg[i]==1)
       output_low(pin_e0);
       
       printf(lcd_putc,msg[i]);//test
       printf(lcd_putc,"\n%c",msg[i]);//test
       printf(lcd_putc,"%d",msg[i]);//test
       delay_ms(200);
       }
       
    }
   
       
    }
    rs485_no=1;//for habilitate the "false"
   
   
        delay_ms(300);
        output_high(pin_e0);
        delay_ms(300);
   }
}

and my hardware:


I did several examples, tried different ways but could not get a good job...

Thankful since already =D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 16, 2013 12:57 pm     Reply with quote

This looks like, I would guess, a Proteus project.

But anyway, I looked at your schematic and your LCD is connected
wrong. You have pin 1 (Vss) connected to Power, and you have pin 2
(Vdd) connected to ground. In other words, you have Power and
ground reversed on the LCD. Be thankful if this is Proteus because if
it was for real, the LCD would likely be destroyed.
temtronic



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

View user's profile Send private message

PostPosted: Fri Aug 16, 2013 3:51 pm     Reply with quote

PCM_P has better eyes than me !

Man, I really,really HATE Proteus !
When I quickly scanned the schematic, I concluded he had all 3 pins (1,2,3) of the LCD tied to ground and 'earth'.
I was taught that a triangle pointed down was ground NOT VCC...
Seems nowadays it can be at any compass direction(N,S,E,W) !

Not to mention the 'rat's nest' for the rest of the 'wiring' to the LCD..which is very hard to follow.
It 'should' be a simple matter to 'draw' straight lines to 'wire' the LCD to the PIC without crisscrosses,overlaps,etc.
The nicer,cleaner the schematic the EASIER it is for everyone to follow.

Also... it's unlikely you need to 'double up' the bias resistors for the RS-485 network...

hth
jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Aug 17, 2013 3:09 am     Reply with quote

You're wasting our time and yours with ISIS/Proteus.

Throw Proteus away, come back when you've tried with real hardware.

On your schematic you're not showing either decoupling capacitors or any kind of oscillator.

A simple "program dont work... " gives us no clues.

Read the forum guidelines.

The more you tell us the better we can help.

Mike
SherpaDoug



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

View user's profile Send private message

PostPosted: Sat Aug 17, 2013 5:03 am     Reply with quote

If you have real hardware see if the A and B lines move at all. What is their voltage level? If you have a scope is the length of the data burst consistent with the baud rate?
_________________
The search for better is endless. Instead simply find very good and get the job done.
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