Crumbuino mega serial 485 questions

Hey guys, I am pretty experienced with the arduino so far, but I do have a problem with the crumbuino mega at the moment.

The integrated rs485 seems to works fine from a coding point of view, as long as I just want to write on the 485 bus. This proves, that the bus setup is done right and the pins are connected the right way.

But reading on the bus doesn't work. Any ideas what could be wrong? Coding itself isn't the problem it seems to be that case that I need to maybe set a read write pin to change from writing to reading mode, but I do not find the pin to set, or anything else that could cause the problem.

For a test of the code, I use the internal serial bus via USB connector which proves that read and write code works fine on that rs485 connection....

Any ideas?

What is a crumbuino?

Post your code.

...R

Crumbuino is a small version of an arduino with full compatibility

https://www.google.de/search?q=crumbuino&safe=off&biw=1920&bih=969&tbm=isch&tbo=u&source=univ&sa=X&ved=0CEkQ7AlqFQoTCK-Z96Km38YCFSdw2wodyGYMvg&dpr=1

while (Serial3.available()>0)
    {
        char c = (char)Serial3.read();
        if (check(c))
        {
            Serial.print( (char) c);
            received_Command_Serial += (char)c;
        }
    }

    while (Serial.available()>0)
    {
        char c = (char)Serial.read();
        if (check(c))
        {
            Serial3.print((char)c);
            received_Command_Serial += (char)c;
        }
    }

As you can see, the code is quite simple and just for testing pruposes. Serial is the internal serial bus via USB, Serial 3 is a RS485 bus. On the internal bus, read and write works fine, on the RS485 Serial 3 bus, only writing works, but no reading.

So, anything is write into the Serial console gets printed out via RS485, but all I send via RS485 (Tera term for example) seems to be lost.

As you can see, the code is quite simple

Even such simple code has several things that cause one to go hmmm.

        char c = (char)Serial3.read();

The explicit cast is not necessary. Since the call to read() happens inside a block that is executed only when there is data to read, the high order byte of the int that read returns will always be 0, so the low order can be saved in a char with no loss of information, without the need for a cast.

Its just like storing a floating point variable's contents in an int variable. An implicit cast will be performed. An explicit cast is not needed.

            Serial.print( (char) c);

Casting a char to a char just looks stupid.

            received_Command_Serial += (char)c;

Using Strings goes beyond just looking stupid.

I know about the code not looking good. But I tried several things to deal with the issue that I cannot get something read from the serial3 bus. This is no productive code, just for testing and playing purposes. It works fine with the Serial, but not with Serial3, so it would be great if the focus could be on problem solving.

It works fine with the Serial, but not with Serial3, so it would be great if the focus could be on problem solving.

Is it safe to assume that you have actually connected the data source to Serial3's pins?

Of course.

And I can already use the Serial3 Bus to write data on it, so everything is connected the right way. Only reading is the Problem...

And I can already use the Serial3 Bus to write data on it, so everything is connected the right way. Only reading is the Problem...

I'd connect an FTDI cable to the Serial3 pins, and see if the issue is a damaged serial port.

j_witt: And I can already use the Serial3 Bus to write data on it, so everything is connected the right way. Only reading is the Problem...

Does your code work properly on (say) Serial2 ?

If so it suggests thet Serial3 is broken. If not then the problem is with the code.

The examples in serial input basics may be useful.

...R

The code works fine with Serial. Read and Write already tested. I think it has something to do with the read/write pin of the RS485 IC, which is a 75lbc176 on the crumbuino and the RE/DE pin is internally connected with PCINT11, so it seems I cannot set it manually to hIgh and low...or something similar.

j_witt: I think it has something to do with the read/write pin of the RS485 IC, which is a 75lbc176 on the crumbuino and the RE/DE pin is internally connected with PCINT11, so it seems I cannot set it manually to hIgh and low...or something similar.

In Reply #2 you posted a link to pictures of a Crumbuino - which don't provide any useful advice for solving your problem.

Post a link to the datasheet for the device - particularly the parts that explain how to use the RS485 stuff.

...R

This is all that is available:

http://download.chip45.com/Crumbuino-128_infosheet.pdf

j_witt: This is all that is available:

Is your device identical to that PDF. It uses an Atmega128 whereas a Mega uses an Atmega2560 ?

It says you need to connect jumpers to get the RS485 to work - have you done that ?

From a software point of view is RS485 any different from RS232 ?

...R

j_witt: The code works fine with Serial. Read and Write already tested. I think it has something to do with the read/write pin of the RS485 IC, which is a 75lbc176 on the crumbuino and the RE/DE pin is internally connected with PCINT11, so it seems I cannot set it manually to hIgh and low...or something similar.

You have to manually switch the RE/DE to change from transmit to receive, that datasheet says:

The module comes with an SN75ALS176 RS485 transceiver onboard. It is connected to the MCU's second USART RXD1/PD2 and TXD1/PD3 as well as PD4 to control the transceiver transmit or receive mode. Four jumpers J1 to J4 are used to disconnect the signals plus the transceiver's VCC from the MCU to fully disable the RS485 transceiver and allow for other usage of the USART signals. The four jumpers are open by default, thus disabling RS485. If you want to use RS485, close all four jumpers!

So there's no difficulty driving, close all the jumpers and do

pinMode (4, OUTPUT) ;

to drive the direction pin, and set it appropriately.

[assuming PD4 is mapped to Arduino pin 4 like the Uno]