I have made some projects and they work very nice.
Now, I have a project where I need RS485 communication and I heve a problems!
First I tried to switch to transmit in the begining where I send ant to switch to receiving on the end of this word. But it didn't work. Probbably I lose XON and XOF and also 'emit' write character in buffer and it will be transmited later in irq.
After that I looked in asm file and thought that I need to put switching in 'asmemit':
;;; ************************************************
asmemit:
btfss PIR1, TXIF, A
bra asmemit
btfss PIR1, TXIF, A
bra asmemit
bcf h'f80', 4, A ; ZM Switc on transmit for 485.
movwf TXREG, A
asmemitZM:
btfss PIR1, TXIF, A ; ZM Wait until char is transmited.
bra asmemitZM
bsf h'f80', 4, A ; ZM Switc on receiving for 485.
return
but it didn't work.
In this case I can work without XON/XOFF.
If you hav an idea (and time), pleas tell me.
Thank you very much.
Zoran
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is a chrome plating plant. There are 20 regulated switching current sources (0 to 100A), one control unit and PC (Delphi6). Control unit and PC can be master (one of them). Control unit and switchers are with 18F2520. RS485 is with 75176 chip and optocoupled. Porta,4 is used for RX/TX switching. On PC side RS485 is with 75176, max232 and SN555 (automatic switching RX/TX). Speed is 38400 bd.
Control unit has LED 7-segment displays (11) and keys (14) connected to the PIC via I2C. (4xSAA1064 and 4xPCF8574).
I find in data shit: '- Supports RS-485' but I don't know how.
I looked in data sheet and first case seems to be simple but secon (back to back) is tricky.
I try to test TRMT and exit from 'asmemit' but it didn't work.
I tested hw. When I manualy put 5V on TX enable pin transmition is OK.
Now I see that and receiving is now ok!
Hope that you anderstood my explanation.
Zoran
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have not worked with master slave r485 systems.
Since I dont know your protocol it is hard give any further advice.
Maybe you should have some delay after enabling the transmit pin
and before/after transmitting the char ?
Micke
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi dear OM Mikael,
I have made some projects and they work very nice.
Now, I have a project where I need RS485 communication and I heve a problems!
First I tried to switch to transmit in the begining where I send ant to switch to receiving on the end of this word. But it didn't work. Probbably I lose XON and XOF and also 'emit' write character in buffer and it will be transmited later in irq.
After that I looked in asm file and thought that I need to put switching in 'asmemit':
;;; ************************************************
asmemit:
btfss PIR1, TXIF, A
bra asmemit
btfss PIR1, TXIF, A
bra asmemit
bcf h'f80', 4, A ; ZM Switc on transmit for 485.
movwf TXREG, A
asmemitZM:
btfss PIR1, TXIF, A ; ZM Wait until char is transmited.
bra asmemitZM
bsf h'f80', 4, A ; ZM Switc on receiving for 485.
return
but it didn't work.
In this case I can work without XON/XOFF.
If you hav an idea (and time), pleas tell me.
Thank you very much.
Zoran
Hi Zoran,
The TXIF flag only indicates that the transmit register is free.
The character has not yet been transmitted.
The TRMT flag indicates if the actual transmit shift register is empty.
So after you written to TXREG you must wait until TRMT indicates that
the shift register is empty. Look in the (E)USART section of the data sheet.
Is your RS485 simplex or duplex ?
How does the other end of the RS485 know when to switch between RX/TX ?
Is there special HW for that ?
73s Micke
Hi Mikael
and tnx for expres answer.
I will explane what I am doing.
It is a chrome plating plant. There are 20 regulated switching current sources (0 to 100A), one control unit and PC (Delphi6). Control unit and PC can be master (one of them). Control unit and switchers are with 18F2520. RS485 is with 75176 chip and optocoupled. Porta,4 is used for RX/TX switching. On PC side RS485 is with 75176, max232 and SN555 (automatic switching RX/TX). Speed is 38400 bd.
Control unit has LED 7-segment displays (11) and keys (14) connected to the PIC via I2C. (4xSAA1064 and 4xPCF8574).
I find in data shit: '- Supports RS-485' but I don't know how.
I looked in data sheet and first case seems to be simple but secon (back to back) is tricky.
I try to test TRMT and exit from 'asmemit' but it didn't work.
I tested hw. When I manualy put 5V on TX enable pin transmition is OK.
Now I see that and receiving is now ok!
Hope that you anderstood my explanation.
Zoran
I have not worked with master slave r485 systems.
Since I dont know your protocol it is hard give any further advice.
Maybe you should have some delay after enabling the transmit pin
and before/after transmitting the char ?
Micke