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

max485 connection to PIC16f877

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







max485 connection to PIC16f877
PostPosted: Thu Jan 19, 2006 9:33 pm     Reply with quote

i am confuse what pins of max485 needed to be conected to my PIC16f877...so that i can comunicate with my other PIC16f877..

For both PIC...there a LCD and a keypad each...it will be great if u can give me a source code so i can comunicate with my two PIC..thanks Surprised

HEres a data sheet of max485..

http://pdfserv.maxim-ic.com/en/ds/1111.pdf
Been There
Guest







'485 Comm
PostPosted: Mon Jan 23, 2006 1:01 am     Reply with quote

The first question is whether you can afford 4 wires between your '485 devices. If so, then the '485 parts are more like drivers.

The next question is if you are doing a master / slave arrangement then the 2 wires is ok. If either side has to talk, then you need to stick with the 4 wire arrangement.

If you are limited to 2 wires for communication between your PICs, then you have to switch between transmit and receive (-RE & DE).

As to the ports, use the TX and RX ports just as you would if you were interfacing with a RS232 port. There are tons of free code examples on the web. Try looking at the MicroChip site.
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

PostPosted: Wed Jan 25, 2006 1:55 am     Reply with quote

Quote:
If you are limited to 2 wires for communication between your PICs, then you have to switch between transmit and receive (-RE & DE).

i dun understand this part...can u explain?

yes im using master/slavce arangement...heres my connection from max485 to PIC18f452...since theres not enough ram to compile for PIC16f877...

RO-RC7
-RE-RC4
DE-RC5
DI-RC6
pin5-GND
pin8-VCC

THe rest of the pins goto other max485, A-A, B-B...
heres my soure code for master

Code:
//master
#include<18f452.h>

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock = 20000000)
#define RS485_ID  0x10                 // The device's RS485 master address
#define RS485_USE_EXT_INT TRUE        // Select asynchronous serial interrupt

#include<RS485.c>
#include <lCD420.c>

int buffer[40];
int next_in  = 0;
int next_out = 0;

#INT_RDA
void serial_isr()
{
   int t;

   buffer[next_in] = fgetc(RS485);
   t = next_in;
   next_in = (next_in+1) % sizeof(buffer);
   if(next_in == next_out)
      next_in=t;        // Buffer full !!
}

void main(void)
{

   int j;

   int data_received[32];
   lcd_init();

   //enable_interrupts(INT_RDA);
     // enable_interrupts(GLOBAL);


   rs485_init();

   while(1)
   {

      rs485_wait_for_bus(FALSE);

                   //send address=0x11, length = 1, msg=3
                               
      if(rs485_send_message(0x11, 1, 3))
      {

         /*output_low(PIN_B1);
         delay_ms(100);
         output_high(PIN_B1);
         delay_ms(100);
         output_low(PIN_B1);*/

         lcd_gotoxy(1,3);
         printf(lcd_putc, "\n\rADC (V):test\r\n");
         delay_ms(100);
      }

      delay_ms(5);


      if(rs485_get_message(data_received, FALSE))
      {
         for(j=0;  j<3; ++j)
                  data_received[j] = buffer[j];


               if(data_received[2]==6)         //if slave receives the number 3 successfully
         {                    //slave will send back number 6
            lcd_gotoxy(1,4);
            printf(lcd_putc, "\n\rADC (V):test\r\n");
            delay_ms(100);

            /*output_low(PIN_B2);
            delay_ms(100);
            output_high(PIN_B2);
            delay_ms(100);
            output_low(PIN_B2);*/
         }
      }

         }
}


and heres the slave..

Code:
//slave
#include<18f452.h>

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock = 20000000)
#define RS485_ID  0x11                 // The device's RS485 slave address or ID
#define RS485_USE_EXT_INT TRUE        // Select asynchronous serial interrupt

#include<RS485.c>
#include <lCD420.c>

int buffer[40];
int next_in  = 0;
int next_out = 0;

#INT_RDA
void serial_isr()
{
   int t;

   buffer[next_in] = fgetc(RS485);
   t = next_in;
   next_in = (next_in+1) % sizeof(buffer);
   if(next_in == next_out)
      next_in=t;        // Buffer full !!
}

void main(void)
{

   int j;

   int data_received[32];
   lcd_init();
  // enable_interrupts(INT_RDA);
      //enable_interrupts(GLOBAL);

   rs485_init();

   while(1)
   {

      if(rs485_get_message(data_received, TRUE))
      {

         for(j=0;  j<3; ++j)
                  data_received[j] = buffer[j];


         if(data_received[0] == 0x11)
         {
            lcd_gotoxy(1,4);
            printf(lcd_putc, "\n\rADC (V):test\r\n");
            delay_ms(100);
            /*
            output_low(PIN_B2);
            delay_ms(100);
            output_high(PIN_B2);
            delay_ms(100);
            output_low(PIN_B2);
          */

            rs485_wait_for_bus(FALSE);


            //after receive successfully, respond to master by sending number 6
            if(rs485_send_message(0x10, 1, 6))
            {

               lcd_gotoxy(1,3);
               printf(lcd_putc, "\n\rADC (V):test\r\n");
               delay_ms(100);

              /* output_low(PIN_B1);
               delay_ms(100);
               output_high(PIN_B1);
               delay_ms(100);
               output_low(PIN_B1);
               */
            }
         }
      }

         }
}
Muhammad Ashraf Khatri



Joined: 26 Jan 2006
Posts: 1

View user's profile Send private message MSN Messenger

PostPosted: Thu Jan 26, 2006 1:21 am     Reply with quote

what can we do if 1 is master and more then 1 are in slave configuration
how can we then program
funmix



Joined: 27 Mar 2007
Posts: 33

View user's profile Send private message

PostPosted: Fri Apr 06, 2007 5:56 am     Reply with quote

how you verify your code is working? By watching the LED blinking ?
funmix



Joined: 27 Mar 2007
Posts: 33

View user's profile Send private message

PostPosted: Sun Apr 08, 2007 5:43 am     Reply with quote

I tested the code. I found that the led of the master keep blinking. It means that master keep receive message only. Slave is doing nothing. I also tested with Hyperterminal, there is nothing display on the window.

Can someone please help?
Ttelmah
Guest







PostPosted: Sun Apr 08, 2007 8:41 am     Reply with quote

There is a potential problem, if you disable the RS485 receiver (you are connecting to this pin, but I have not lookd at what you do with this). Basically, if you disable the receiver, the output pin, goes high impedance. On the TTL serial input of the PIC, the incoming line needs to be _high_ when data is not available. If it drops, this is seen as receive data. If you are going to disable the receiver when sending, you need to add a pull up resistor, or garbage data will be received. In general most people using RS485, do not disable the receiver. Instead, they accept that the transmitting chip wll receive everything it sends, and leave the receiver enabled. Also, with the MAX485, you should be looking at arranging your 485 bus termination, so that a bias is applied to the bus, ensuring that the data output is high, when nothing is being sent, or, there will be garbage data received when the bus is idle. There are some other RS485 receiver chips, that do not require this, and also electronic terminators available, that apply the correct bias to the bus.

Best Wishes
funmix



Joined: 27 Mar 2007
Posts: 33

View user's profile Send private message

PostPosted: Mon Apr 09, 2007 6:18 pm     Reply with quote

Both PICs hardware.
Rx -- RO
Tx -- DI
RC5 -- DE
/RE -- GND
A--A
B--B

Pullup - 0.5K for both A and B buses

This is how i connect in my hardware.
Humberto



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

View user's profile Send private message

PostPosted: Mon Apr 09, 2007 9:23 pm     Reply with quote

Quote:

Pullup - 0.5K for both A and B buses

RS485 do not needs any pull ups resistor.

Quote:

RO-RC7
-RE-RC4
DE-RC5
DI-RC6
pin5-GND
pin8-VCC

To start working and to avoid bus contention, I suggest you to run in Half Duplex Mode,
hence you can atach togheter the DE and -RE pins.
Quote:

RO -RC7
DI -RC6
-RE/DE -RC5
pin5-GND
pin8-VCC


It doesn´t matter to find out errors in your code if the basic hardware is wrong.
There are several considerations that you must take care and know prior to try with RS485,
that is out of the scope of this forum. I suggest you to study the RS485 phisical layer.
Once you understand it you will know how easy is to implement a communication bus.
You will find a lot of info in the web.

http://www.lammertbies.nl/comm/info/RS-485.html
http://www.bb-europe.com/bb-euro/literature/485appnote.pdf
http://www.embeddedsys.com/subpages/resources/images/documents/microsys_art_RS485.pdf
http://www.interfacebus.com/Design_Connector_RS485.html


Humberto
Ttelmah
Guest







PostPosted: Tue Apr 10, 2007 2:27 am     Reply with quote

There is only one 'bus'. A, and B, are a differential _pair_ of signals, comprising just a single data path. There should be termination _between_ these signals at the ends of the bus, matching the characteristic impedance of the wiring used. Normally 100R. This becomes essential at high data rates, but for simple testing at low rates, the system may operate OK without it.
Now a _slight_ pullup on one line, and a pull down, on the other, will ensure that the bus 'idles' to the 'off' state. You want the 'A' line pulled down, and the 'B' line pulled up, and the resistors should be chosen to give 200mV at least between the lines. You can get active terminators that do this. The simplest setup that gives this, is a 1200R resistor from the 0V connection to the 'A' line, 120R from A to B, and 1200 from B to +5v. This gives a characteristic impedance of 100R, and 238mV between the lines.
Pull the application report number SLLA070C from the Texas instrument site, for an overview of other termination methods, and how the bus sould be configured.

Best Wishes
cheehow



Joined: 15 Sep 2010
Posts: 28

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 10:24 am     Reply with quote

HI crushneck,

i m also doing the same things as what u have done it ... so, can u show me ur sucessed codes to me and the circuit diagram as well .. your help would be appreciated !! thxssss Very Happy

Regards
Chee how
Humberto



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

View user's profile Send private message

PostPosted: Mon Nov 08, 2010 10:56 am     Reply with quote

Hi Chee how,
The last time that crushneck posted in this forum was on: Feb 10, 2006 hence you have minimal chance to contact
him through this panel, try to send him a pm or describe your problem in this thread and you will get further help
from another members.

Regards.
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