The debugging option is added to check if the transmission and the system running correctly. But in normal usage it is not used. In fact as you said i dont need two masters. Pc is the master. But according to protocol development i may need a second master. But this (second) master will act as requested. So protocol says no slave device can send info by themselves. This is certain.
As I read in the datasheet of MAX485, it says there is a Fail-Safe circuit inside the chip. This guarantees when there is no traffic, the RO line will be high. I checked this and this is ok. I thougt no biasing needed. Just the termination.
Yesterday night i tried sth and the thing start to work normal. Here are the details:
- First i removed the MAX485 lines and checked with a TTL serial connection.
- Very strange that ATmega328 does not understand the bit pattern even if it receives it.
- I changed the code:
- - According to the protocol a command is formed with:
1 Byte header; which is (byte) 90 --> (char)'Z'
4 Byte address
1 to 6 bytes command
thus:
if (Serial.available()){
//incoming command
byte rec = 0;
rec = Serial.read();
[i]//Serial.print(rec,DEC); /*--> if i uncomment this line i see all data i've sent so data arrives at the chip and it replies back. but no action*/[/i]
//serial data filtering
//first byte must be <Z>
if (rec == 90){
//following 4 bytes must be id
//Serial.println("Serial Data begin"); //--> *
if (checkIdNr()){
//idNr is correct
//Serial.println("ID nr match"); //--> *
//read command
byte serialData = Serial.read();
//...Command Logic....
if i uncomment the lines marked with "--> * " the device works properly. I mean, it reacts all of the commands that pc send to it. I need to do some tests also this evening. and will report later. I think that this is related with transmission delay
... This is tricky because you have to know when the transmit buffer is empty and all of the last byte has been sent...
. ATmega328 works at 16MHz and it is faster than a 80286

For normal operation if a slave is requested to reply, it first pulls high the outputEnable pin and then sends the data. So even if i uncomment the
"--> * " lines MAX485 does not send any data to PC. Because the chip is in "Listening Mode"
Thank you for the answers