PDA

View Full Version : Serial communication between PIC and Atmega controileer trough RS485



visitac
- 1st October 2012, 23:19
Hello,
I allready post on the melabs forum. But here is another very visit forum, perhaps anyone can help me

Hours try to comunicate to a 7segment display without sucess

I have a 18f4520 on there i conect on Porte.0 and Porte.2 TX and RX pins of a RS485 driver to send data to a 7segment display that have also a RS485 driver.

The direction pin is already output and also high for transmitting
dir_rs485 var PORTE.1 'RS485 Mode
high dir_rs485 'transmitting mode

The 7segment display have a Atmega88P controller. This display works on a network of manys slaves very good, all with Atmega controllers at baudrate 38400.
Now i want to communicate with this display trough a pic 18f4520 on baud 2400. I tried everything like:

disp_pos var PORTE.0 'Tx to a RS485 driver

serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao,13,10]
serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao,13]
serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao,10]
serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao]
serout2 disp_pos,16780,5,[#master,#destino,#posicao,13,10]
serout2 disp_pos,16780,5,[#master,#destino,#posicao,13]
serout2 disp_pos,16780,5,[#master,#destino,#posicao,10]
serout2 disp_pos,16780,5,[#master,#destino,#posicao]

All the same with serout2 disp_pos,396,5,
serout2 disp_pos,33164,5,
serout2 disp_pos,49548,5,
Like i said the display works fine on the Atmega as slave on the Atmegas network

Have the same baud of 2400 on the display

Anyone idea what i make wrong on the pic code?
Compiled with PBP247

Thanks in advance
visitac

mackrackit
- 1st October 2012, 23:44
http://www.picbasic.co.uk/forum/showthread.php?t=561

aratti
- 2nd October 2012, 04:58
It is not too clear, from your post, the question of the baud rate. If your RS485 existing network, works at 38400 bauds then you must Tx out your commands at the same speed. This means you cannot use 2400 bauds.

If I have corectly understood the baud rate question, then you will never reach that speed with serout2. You will need to use the hserout comand which use the Hardware USART.

Cheers

Al.

visitac
- 2nd October 2012, 10:16
Hello aratti,

On both boards have the same baud of 2400. I have write about the 38400 baud to show you that the 7segment display board works on other network with baud of 38400. For this project i have changed the baud to 2400 like the baud on the Pic controller.

Best regards
visitac

mackrackit
- 2nd October 2012, 10:31
Did you check the ADC ?

visitac
- 2nd October 2012, 15:33
Hello mackrackit,

I write on start of the programm ADCON1 = 7
You mean that?

Best regards
visitac

aratti
- 2nd October 2012, 17:23
..OK, all your network devices works at 2400 baud. First question: did you put the two 620 ohms resistors on the head and tail of your network? Remember that you need to connect a pullup on channel A and a pulldown on channel B at the extreme of your network.

Next remove the "pace" value form your code. Between placing high portE.0 and the serout comand, place a 2 - 5 milliseconds delay using "PAUSE 5"

Cheers

Al.

visitac
- 2nd October 2012, 22:07
Hello aratti,

Yes i have the pulldown and the pullup resistors connect, not solve

with this i receive on the display the data on the atmega88 controller that works as slave

_start:

If Ischarwaiting() <> 0 Then 'test if char arrive
Inputbin Serialchar 'get it
If Serialchar <> 254 Then Goto _start 'the first value must be 254
Inputbin , T_destino , Crypt 'get the rest two values
Clear Serialin
End If


the works as master, and send this binary data

i try to send it as decimal as too hex
serout2 disp_pos,396,[dec master,dec destino,dec posicao]
and also
pause 1000
serout2 disp_pos,396,[hex2 master,hex2 destino,hex2 posicao]

unfortunatly without sucess

I have no more idea what can be wrong

Best regards
visitac

aerostar
- 3rd October 2012, 09:09
Just a thought, if you have accidently crossed the rs485 wires, then the signal will be inverted at the receiving end, so your serial data would be inverted.

aratti
- 3rd October 2012, 17:32
With fragment of code and no schematic, I personally think you cannot get much more help. Please post the whole code you are using, along with some reference to the data sheet of the slaves you have installed in your network. Naturaly complete the info with a schematic on the setup.
With a more complete picture you will have a better chance to get the corrected advice.

Cheers

Al.

visitac
- 4th October 2012, 20:48
Hello aratti,

The network is only one master, the pic controller, on there i use serout2 and a 7segment display as slave, that use a Atmega88P. Both with baud 2400
The display works fine on other project as slave too on baud 38400, all with Atmega controllers. The display is not a problem, the protocol is the same,
only on this project with the pic i have change the baud to 2400. With software uart it not possible to work on baud 38400. Why i have change the baud on the
display to 2400.

I can draw a schematic tomorrow, but like i said the display is working on the other project. On the board with the pic i have connect PORTE.0 to pin 4 and PORTE.2 to pin 1
of the max487. The pin 2 and 3 of the max487 connect together to PORTE.1. On startup make the PORTE.1 as output and high for transmit mode. A is connected to A and B to B of the max487 on the display.

Best regards
visitac

Dave
- 5th October 2012, 11:34
Pullup and Pulldown resistors are mearly safeguards for disconnect conditions. I do not hear of any bus termination resistors in place? There should be a termination resistor on each END of the bus between bus+ and bus-. I would a quick verification of the IDLE state of the bus by allowing it to go IDLE (with no traffic) and look at the RX output pin of the MAX487 to make sure it is in the correct IDLE state. This will infact tell you if the bus connections are reversed. SERIN statements do not act very well when they are in the reversed states. The program tends to hang. I would also place a pullup resistor on the RX pin of the PIC to ensure it's state during the time the TX enable of the MAX487 as the RX output line will go tristate.

visitac
- 6th October 2012, 15:47
Hello,
Thanks to all that try to help. For Feedback purpose,

Now it works, but not with Serout2 but trough debug,

' Set Debug pin port
DEFINE DEBUG_REG PORTE
' Set Debug pin bit
DEFINE DEBUG_BIT 0
' Set Debug baud rate
DEFINE DEBUG_BAUD 2400
' Set Debug mode: 0 = true
DEFINE DEBUG_MODE 0

debug master,destino,posicao 'this works


disp_pos var PORTE.0 'TX
dir_rs485 var PORTE.1 'RS485 tx Mode
high dir_rs485 'set to transmit mode
serie_in var PORTE.2 'RX 'not need in this project

serout2 disp_pos,396,[master,destino,posicao] 'dont't work

Not idea why serout2 not work.

Best regards
visitac