Go Down

Topic: Arduino with two uC. Problem with communication. (Read 689 times) previous topic - next topic

Rubid

Hi guys,
in my recent project I need to implement my own arduino, but instead of one Atmega I need two of them. The first one will be used to read some info from the FT232 chip and then move the stepper motors according to that info. But when the first uC controls the motors, the loops are in progress so it cannot read at the same time. Thats why i need a second one to eventually cut off the power from the first uC (ex. using a transistor) in a really "emergancy" situation.

Question:
Can it be done? Can I connect two uC to RX and TX lines of FT232?
If so, where to put pull up resistors? Can the value be the same as for one uC (1k)?

Please help.

pylon

Quote
Thats why i need a second one to eventually cut off the power from the first uC (ex. using a transistor) in a really "emergancy" situation.


This is not necessary it you write the software correctly. What's an "emergency" situation in that context?

Rubid

I thought that it is the safest way to do that sort of things - one uC controling the motors, and the second one waiting for an error message sounds logical.
I don't know how could I write a software for uC where I'm processing the loop (to move the stepper motor) and in the same time reading the incoming messages to RX pin.

An "emergency" situation occures when a limit switch is pressed by a platform, or simply when the user wants to stop the motors from Java app on his PC.

How can you perform while(Serial.available() > 1) {do sth} while doing this:

        for(i=0; i<=y; i++){ // move x motor
          digitalWrite(6, HIGH);
          delay(timeout);
          digitalWrite(6, LOW);
          delay(timeout);
        }

?

pylon

Quote
How can you perform while(Serial.available() > 1) {do sth} while doing this:


By not using delay(). An example of an implementation:

Code: [Select]

uint32_t last_millis = 0;
uint16_t i = 0;
uint8_t state = 0;

void loop() {
  if (Serial.available()) {
    // react on the character from the serial interface
  }
  if ((i << 1) < y && millis() - last_millis >= timeout) {
    i++;
    last_millis = millis();
    state = ! state;
    digitalWrite(6, state);
  }
}

Rubid

Thanks pylon - the implementation you've posted is really good! I'll try this as soon as I can.

OK, but apart from that - is it possible to connect several uC to one FT232 (or a "master" uC)?
If so, where would you put pull up resistors?

See attached schema.

Go Up