interfacing pc to pic using RS485 (help me)

Status
Not open for further replies.

amrshata

Member level 1
Joined
Aug 9, 2011
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,501
hi every one i have a problem that i can't find any solution for it i try to connect pc to mcu using rs485 line as it have long distance
efficeiny so i bought usb to rs485 converter .. and bought max485 .. to make the interface between them as shown in the picture

i tried two ways ... first by consdering it's normal uart interface and i used the interface modules in mikroc . and i got errors ..
first as RC2 are not defind for normal uart interface .. so when i connect it with resistance 10k to volt .. errors occure too
.. that i recevie .... start repeated many times




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
char uart_rd;
void main() {
  ANSEL  = 0;                     // Configure AN pins as digital  ANSELH = 0;  
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize  
  UART1_Write_Text("Start");
  UART1_Write(10); 
 UART1_Write(13);  
  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // read the received data,
      UART1_Write(uart_rd);       // and send data via UART    } }}



output on virtual terminal

03:38:00 …ÉÑ)
03:38:04 art
03:38:12 Ñ…ÉÑ)
03:38:14 Starô
03:38:15 ¡ø
03:38:16 —¨ø
03:38:17 Start


and as i write on virtual nothing recevied





second i used the RS485 modules in the mikroc .. where here i have problem as when i send from master (pc) to slave (pic) .. i must
define the slave address in the virtual terminal ... and i can't find a way to do so in mikroc . .. .. guys .. please help me

 
Last edited:

Do you understand the concept of RS485? How do you control the direction the traffic?
 

yes i think ,, (( RS485Master_Send(dat,1,160); )))

by identify the slave address while sending
 

How do you control the direction the traffic?
 

sorry i can't understand you ... here in rs485 there are many slaves and one master ... the master while sending specify the direction of data by typing the address of slave he want to send to him like if i have 5 slaves ... 161 162 163 164 165 ... i want to send to third one only i write ... RS485Master_Send(dat,1,163); ... and the is an address for broadcasting ... all that can be done by using pic to pic .. but my problem here that i can't make my pc master ... i dont know how to do so in virtual terminal of mikroc
 

OK, I have no experience with mikroc, don't even know what it is.
A few years ago I wrote some software for a PC to be master on a multibus network. It wasn't trivial to get it to turn the RS485 buffer the correct way with correct timing.
Many people don't even understand the function of RS485.

This function RS485Master_Send(), is it something you got from the supplier of your USB to RS485 adapter?
 

here in my project yes ... but generally .. it's the way master send information to slaves .. where i could interface 32 device in the same time on the same line to one master
 

First try to just receive data from the PC in your PIC.
 

i tried so .. but i recevie someting strange .. when i send((start)) ... it's received but with errors
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…