UART between ATMEGA and ATMEGA through DUE

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,

I have two atmega boards, and one atmega board - A can be directly connected to the UART. The other board- B has only extension pins and I connect its UART pins to DUE's UART pin as in the picture(UPLOAD). Both the boards are connected through zigbee and i want to test. The A displays menu as like in figure 2 but B does not display as like in figure 3. It can take the inputs like 't' transmission and 'r' reception. But cannot display the sub-menu . I flashed both the boards with same software. How can B display same like A ? the baud rate is proper. What changes to be done in UART setings ? I checked for baud rate and clock. The arduino DUE clock is 4mhz . My atmega board works with internal RC and then at the beginning of the program I added # define F_CPU 4000000 . Is there anything whic´h can be done ?

 

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First, using internal RC with serial comms is a bad idea, as the chosen clock source is not stable or accurate enough, when using serial (USART) comms, always use a xtal clock source!

Second, how can we possibly tell you what is wrong without seeing the code?  (please post using the "<>" from the edit menu. 

Third, it is always best to get your serial comms working first with hardwire connections, then once it is working, add the radio link as that will add many more problems.

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my arduino code

 

< char rx_byte = 0 ;        // stores received byte

void loop() {

   //testread
  // check for data byte on USB serial port
  if (Serial.available()>0) {
    // get byte from USB serial port
    rx_byte = Serial.read();
    // send byte to serial port
    Serial.write(rx_byte);
    //Serial.write("\n");
    delay(100);   
    }
} >
 

Changing the fuses to xtal clock source did not help. The exact problem that is happening is that the UART is being overwritten.

I am using this http://www.atmel.com/Images/Atme...

The program for my AVR is the hex file of the software of MTK.

 

I have added a new picture of what is displayed on my screen. kindly take a look at it.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks like your trying to share the same comm channel to two different mpu's, how will each know which one your trying to talk too? 

You need a way to tell the first to ignore "commands" and just pass data through to the other and back, but then you need a way to "escape" to tell the first, ok, I'm now talking to you!

This problem was solved back in the old days with dial up smart modems using three "ESC" characters in a row to tell the smart modem, hey I want to send you a command.

You need to decide how you will direct data flow to each mpu along the comm path!

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the post. What I thought I am doing is , the data from 1st mpu (avr) is read by the 2nd mpu(arduino) and arduino displays on the serial port . Arduino is used as the avr's serial terminal.  It would be helpful if you could provide any links or suggest any "keywords" to google the issue.

 

One general question ,

# define F_CPU 4000000 does this line sets the clock to 4 Mhz in AVR ?

 

 

Last Edited: Fri. Nov 3, 2017 - 02:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pika wrote:
# define F_CPU 4000000 does this line sets the clock to 4 Mhz in AVR ?

 

NO!  it only tells the compiler what speed the cpu should be running at for calculations with timers and delays.

The cpu speed is changed by (1) writing a value to the CLKPR register if it has one, or (2) setting fuses (clk/8 - default on) or (3) fuses to set external clock or xtal.

 

If you use the serial monitor in the Arduino IDE, it connects via USB to USART0 of the Arduino, you will need to use another USART (if it has another(MEGA), or softserial if it does not (UNO)) to connect to the second atmega.

The Arduino will need a program to pass data from first USART to second USART and onto the atmega.  Does that make sense?

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I have to reconfigure clcok for this. Just like the baud rate. I think the clocks are not matching for both mcu. This may be a problm,I guess

 

The Arduino will need a program to pass data from first USART to second USART and onto the atmega.  Does that make sense?

I just used one port TX0 and RX0 . I transmit and receive the data from ATMEGA to ARDUINO and display on the serial terminal with this. So I should use two ports,

1. Arduino transmits / receives data from/to atmega in one port (port 0) . (I have connected tx and rx pins to port 0)

2. the read should be written on another port (port 3) for the display on serial terminal. (The data from port 0 must be sent to port 3 )

 

Is this right ?

 

 

Last Edited: Fri. Nov 3, 2017 - 04:29 PM