View previous topic :: View next topic |
Author |
Message |
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Jan 01, 2019 12:56 am Post subject: Config RS485 not working as expected |
|
|
Code: | $regfile = "m2560def.dat"
$hwstack = 900
$swstack = 700
$framesize = 500
$crystal = 16000000
$baud = 57600
$baud1 = 57600
Open "COM2:" For Binary As #1
'config RS485 print
CONFIG PRINT1 = PORTJ.2 , Mode = SET
CONFIG PORTJ.2 = Output
Print "PINJ.2 START " ; PinJ.2
Print #1, "Test"
Print "PINJ.2 END " ; PinJ.2 |
Result:
PINJ.2 START 0
PINJ.2 END 0
Code: | $regfile = "m2560def.dat"
$hwstack = 900
$swstack = 700
$framesize = 500
$crystal = 16000000
$baud = 57600
$baud1 = 57600
Open "COM2:" For Binary As #1
'config RS485 print
CONFIG PRINT1 = PORTJ.2 , Mode = RESET
CONFIG PORTJ.2 = Output
Print "PINJ.2 START " ; PinJ.2
Print #1, "Test"
Print "PINJ.2 END " ; PinJ.2 |
Result:
PINJ.2 START 1
PINJ.2 END 1
This doesn't appear to be correct
(BASCOM-AVR version : 2.0.8.1 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Tue Jan 01, 2019 1:47 pm Post subject: |
|
|
Hi Ken,
I don't think this is the correct way to test.
Setting and resetting of the J2 pin is all done in the line Print #1, "Test", reading the pin before and after doesn't make sense because Bascom has done it all in 1 single line.
Looking in the Bascom simulator you can see that PORTJ register is set to 4 and then back to 0 in an eyeblink. So it looks to me that this code is working.
To be sure you need to test it with a scope and some realhardware. I can't test it here on a Arduino mega because J.2 is not routed to a header.
Happy new year _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Tue Jan 01, 2019 6:17 pm Post subject: |
|
|
The above example of config using RESET does actually send the data out COM2, while SET does not. HOWEVER, setting it up with RESET doesn't allow receiving on the RS485 buss while config'ing with SET allows for RX but not TX, which would confirm what my print statements are showing
The below also works (verified on actual hardware) for both TX and RX on the RS485 buss (using an ST485 as my device)
Code: | $regfile = "m2560def.dat"
$hwstack = 900
$swstack = 700
$framesize = 500
$crystal = 16000000
$baud = 57600
$baud1 = 57600
Open "COM2:" For Binary As #1
RE_DE Alias Port J.2
RE_DE = True
WaitMs 5
Print #1, "Test"
WaitMs 5
RE_DE = False |
I'll try the code in my OP while watching J.2 with a scope to see what I see |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Jan 01, 2019 6:33 pm Post subject: Re: Config RS485 not working as expected |
|
|
KenHorse wrote: | Result:
PINJ.2 START 1
PINJ.2 END 1
This doesn't appear to be correct |
Yes, this is not correct, because you have shown the wrong result.
The proper first output for this code:
Code: | CONFIG PRINT1 = PORTJ.2 , Mode = RESET
' ...
Print "PINJ.2 START " ; PinJ.2
Print #1, "Test"
Print "PINJ.2 END " ; PinJ.2 |
is:
Quote: | PINJ.2 START 0
PINJ.2 END 1 |
Actually it's a weakness of the code proving you wrong.
The weakness consists in the fact, that only by setting PortJ.2 to output, PortJ.2 is still low, while for the client requiring an active-low, it has to be set high at idle.
For Mode = Reset the user has to set this pin early in code.
Before entry of Print #1, "Test" the PortJ.2 pin is thus 0, within Print #1, "Test" it is driven low (again), as configured by Reset.
After the last byte was sent out from UART, PortJ.2 is driven high, just before Print #1, "Test" exits.
This describes only one loop, as in your code there is no other (intentional) loop.
In your code is no End or Do:Loop either, so code execution after Print "PINJ.2 END " ; PinJ.2 runs into Bascom's core-routines.
Simulation has shown, that the controller runs into invalid opcode and eventually resets, exclusively these error-induced runs following up, may find the pin to be preset correctly.
Described 'weakness' does obviously not occur with parameter Mode = Set, as there the handshake-pin is already set correctly to 0 from the start.
The reason I point it out is not for you, Ken, as I couldn't care less about your problems, neither I care whether you are able to understand my remarks.
I point it out for other users, so they do not fall for your nonsense.
Finally: Config RS485 is working exactly as expected, the bug sits behind the screen. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Jan 01, 2019 6:50 pm Post subject: |
|
|
MAX485 and SN65176B needs RE_DE to be LOW when transmit, and HIGH when receiving.
Because ArduinoMega with Mega2560 dont have PORTJ.2 I connect LED into PORTJ.1 for test.
Even scope is not needed. LED blink like it should. Every sec.
If you communicate two AVRs then device that receive some message, which need response, should wait with this response for a while (eg.5ms)
I know that if I answear immediatelly then line was not ready so messages was corrupted.
Code: | $regfile = "m2560def.dat"
$hwstack = 900
$swstack = 700
$framesize = 500
$crystal = 16000000
$baud = 57600
$baud1 = 57600
Open "COM2:" For Binary As #1
Re_de Alias Portj.1 'LED in my case
'config RS485 print
Config Print1 = Portj.1 , Mode = Reset
Config Portj.1 = Output
Do
Print #1 , "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Wait 1
Loop |
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Jan 01, 2019 6:59 pm Post subject: |
|
|
KenHorse wrote: | Code: | $regfile = "m2560def.dat"
$hwstack = 900
$swstack = 700
$framesize = 500
$crystal = 16000000
$baud = 57600
$baud1 = 57600
Open "COM2:" For Binary As #1
RE_DE Alias Port J.2
RE_DE = True
WaitMs 5
Print #1, "Test"
WaitMs 5
RE_DE = False |
|
Btw., this 100% real code LOL, again does not compile.
As you pity me, I tell what your problem is:
It's a hardware issue, your transmitter, maybe also receiver is simply not ready fast enough.
With Bascoms Config Print the handshake is activated just 3.7µs@16MHz before the UART sends first bits.
Can be fixed by enabling the handshake earlier.
Code: | $regfile = "m2560def.dat"
$hwstack = 900
$swstack = 700
$framesize = 500
$crystal = 16000000
$baud = 57600
$baud1 = 57600
Open "COM2:" For Binary As #1
CONFIG PRINT1 = PORTJ.2 , Mode = SET
CONFIG PORTJ.2 = Output
PortJ.2 = 1
Waitms 5
Print #1, "Test"
End |
Last edited by MWS on Tue Jan 01, 2019 7:49 pm; edited 1 time in total |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Jan 01, 2019 7:29 pm Post subject: |
|
|
EDC wrote: | MAX485 and SN65176B needs RE_DE to be LOW when transmit, and HIGH when receiving. |
According data sheets it is exactly the contrary for the master.
And we are talking here about the bus-master, right?
The receiver is enabled by pulling RE low, the driver is enabled by pulling DE high.
You should know what the line over RE (receiver enable) means, it is an active-low input, DE (driver enable) is regular, active-high.
As PortJ.2 drives RE_DE and TXD1 of ATM2560 has to drive D(I) of MAX485, a high level on PortJ.2 is required to enable the driver sending data over the bus.
Thus MODE = Set is the correct parameter. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu Jan 03, 2019 5:52 pm Post subject: |
|
|
Yes.
I was only curious if such extendend port is driven by "Config Print" and don`t test on device or even open the datasheet.
I mistook MAX485 for SPI CS pin...simply forget how it should be.
My mistake
Sorry |
|
Back to top |
|
|
techknight
Joined: 21 Apr 2008 Posts: 231
|
Posted: Fri Jan 18, 2019 4:53 pm Post subject: |
|
|
I have NEVER had a problem using RS485 with BASCOM in my stuff. all my products are using an RS485 bus, and work perfectly.
the DE/RE line in my stuff is tied together electrically, and connected to the appropriate port pin that I define in the config print.
Works perfectly fine. I use SN75HVD08 ICs in my stuff.
What I did have to do was insert a little bit of wait states between transmission and expected reception, basically to allow for propagation delay and the bus to settle. Otherwise I get errors. |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Sat Jan 19, 2019 3:32 am Post subject: |
|
|
techknight wrote: | I have NEVER had a problem using RS485 with BASCOM in my stuff. all my products are using an RS485 bus, and work perfectly.
the DE/RE line in my stuff is tied together electrically, and connected to the appropriate port pin that I define in the config print.
Works perfectly fine. I use SN75HVD08 ICs in my stuff.
What I did have to do was insert a little bit of wait states between transmission and expected reception, basically to allow for propagation delay and the bus to settle. Otherwise I get errors. |
Thanks, appreciate the straight forward and helpful response.
I'll look into adding some delay |
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|