|
|
View previous topic :: View next topic |
Author |
Message |
jojos
Joined: 30 Apr 2007 Posts: 64
|
A simple question for RS485 |
Posted: Mon Apr 27, 2009 4:59 am |
|
|
I want to transmit with Rs485 connection the hour that derives from a real time clock ,from the master board, to several other boards which are installed in a big building.Because the data i will send will be the same for all the boards do i have to make a protocol with address e.t.c. or simple i can send from the master board the hour ( Hour and minutes) and simultaneously all the boards will recieve it.
Also i saw in the CCs file rs485.c this part of code
Code: |
#ifndef RS485_ENABLE_PIN
#define RS485_ENABLE_PIN PIN_B4 // Controls DE pin. RX low, TX high.
#endif
#ifndef RS485_RX_ENABLE
#define RS485_RX_ENABLE PIN_B5 // Controls RE pin. Should keep low.
#endif
|
DE and RE pins are connected together .Why in this part of code they assign a different pin for them?
Thank you. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Apr 27, 2009 7:48 am |
|
|
I would do a hybrid. Give all the slaves an address. and also build into the protocol a way to send a broadcast.
That will give some flexibility if things change down the line.
All the slaves will listen for messages with its address AND for the broadcast.
As for the pins. two pins means 4 states.
00 -neither
01 -Transmit
10 -Receive
11 -do both (can't do this)
but it is common to tie them together and say that the usart is either listening or transmitting,((ie never turn off))
and its convenient for us because you can tie this wire directly to the enable pin.
#use rs232(baud=1200,errors,xmit=PIN_C6,rcv=PIN_C7,parity=e,enable=PIN_C5,bits=8,stream=RS485) |
|
|
jojos
Joined: 30 Apr 2007 Posts: 64
|
|
Posted: Wed Apr 29, 2009 4:37 am |
|
|
Thanks treitmey for your response.I have to face a new problem that i can't explain. I stripped out all of my code and left a small part to be easy to read.
I am building this clock with 7 segment displays. If i use the option enable=PInx in #use Rs232 directive the displays goes off when i transmit data .If i dont use enable option and set in my code the enable pin by my self displays are ON and the transmission goes on.Here is the code
Code: |
#include "c:\Big_Clock\16F886.h"
#include <string.h>
#include <stdlib.h>
//INTRC_IO
#fuses INTRC_IO ,NOWDT,PROTECT,NOLVP,PUT,NOBROWNOUT,MCLR//BROWNOUT_SW,BORV27//,BORV27 //INTERNAL OSCILLATOR NO CLOCK
#use delay(clock=8000000)
//#use rs232(baud=9600, parity=N,xmit=PIN_C6 ,rcv=PIN_C7) //,ERRORS)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=9, errors, stream=RS485, enable=PIN_C5)
#bit enable1 =PORTC.3 //7 segment Display enable pins
#bit enable2 =PORTC.2
#bit enable3 =PORTC.1
#bit enable4 =PORTC.0
//#bit sec_dot =PORTA.5
//#bit T_enable =PORTC.5
#define ON 1
#define OFF 0
void main(void);
void init (void);
/////////////////////////////////////////////////////
void main(void)
{
unsigned char k=23,i=1;
delay_ms(500);
init();
delay_ms(1000);
enable1=ON; //TURN ON Display 1
PORTB=0b10001000; //display 1 to the display
//enable_interrupts(INT_TIMER1);
while(1)
{
delay_ms(3000); //Here the display is still On but...
putc('A',RS485); //...when this instruction occurs display goes off
}
}
////////////////////////////////////////////
void init(void)
{
TRISA=0b00010111;
TRISB=0;
TRISC=0b10000000;
PORTB=0;
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
enable1=OFF;
enable2=OFF;
enable3=OFF;
enable4=OFF;
disable_interrupts(GLOBAL);
}
/////////////////////////////////////////////////////////////////////////////////
|
I have De and Re pins connected together
Any thoughts?Thanks again |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Apr 29, 2009 7:44 am |
|
|
That is not how to set tris.
You can use standard output commands
OR
you can use the set_tris commands
OR
you can #byte the tris..
you are not setting the tris.
also since you made a stream, do a fputc('A',RS485); |
|
|
jojos
Joined: 30 Apr 2007 Posts: 64
|
|
Posted: Thu Apr 30, 2009 6:29 am |
|
|
Thanks again treitmey for your response.It solved my problem.I am worried also cause in all my programms i used the wrong ,as you mentioned,way of declaring the TRIS registers.
Probably i will ask some more about Rs 485 later.Hope i am not so annoying.Thanks again. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Apr 30, 2009 8:24 am |
|
|
Just start a new thread once in a while,.. or they tend to get a little long.
Also use the search function to look for the answer to questions.
http://www.ccsinfo.com/forum/search.php |
|
|
|
|
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
|