Pages: [1]   Go Down
Author Topic: Arduino with two uC. Problem with communication.  (Read 583 times)
0 Members and 1 Guest are viewing this topic.
Poland
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Poland
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
        }

?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Code:
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);
  }
}
Logged

Poland
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* schema.jpg (41.28 KB, 661x627 - viewed 12 times.)
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 525
Posts: 26572
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can have two uC on one board, each with RS232 interface, and let them talk to each other via SPI or I2C or Software Serial.
http://www.crossroadsfencing.com/BobuinoRev17 schematic
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is it possible to connect several uC to one FT232 (or a "master" uC)?
If so, where would you put pull up resistors?

Theoretically you can connect two µCs to one FT232 for reading but only one can control the TX line, else you produce a short circuit (one µC is holding the TX low, the other goes high). You can insert resistors in the lines to eliminate that problem electrically but you still have the problem of concurrent writes.

In your case the power cutting µC doesn't need more than reading the serial line, so you should be save with that.

But as I already wrote, with a clever programming and maybe a bit help from interrupts you don't need it and have full control within one µC.
Logged

Poland
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys for help.
Logged

Pages: [1]   Go Up
Jump to: