Serial communication between arduino and avr atmega32

I just wonder if I put my question to the write place.

I have not found an example of a two way communication between arduino 2560 and the other avr board
with atmega32 on it.
There seem to be no problem on talking from computer via usb to the arduino board and visa versa.But howto establish a link between avr board and arduino is my problem.I would like to be able to send and receive by both boards.Any help would be appreciated.

You have not posted a link to the datasheet for the Atmega32 board. The simplest way to communicate with a Mega is probably by using a serial connection.

...R
Serial Input Basics

Thanks for your links"serial basic".
I studied them and copied all in my booklet.My question was using TX and RX of Arduino and that of atmega32.I have connected these serial links together but the codes which performs this send and receive
is my problem.From computer via serial usb is no problem but from Arduino and another board is the case I need some examples. Please!

raminaziz:
but from Arduino and another board is the case I need some examples. Please!

You still have not told us what board the Atmega32 is on?

And you need to provide a diagram showing exactly how you have the the two boards connected.

And you need to post the programs that are on your two boards.

...R

Connect the TX of the atmega32 to on of the RX pins on the arduino mega2560 (don't use serial0 - as that's what's connected to USB serial and it will fight with the USB serial adapter), and vice versa, and connect the grounds (as always).

Make sure the program on both boards is communicating on the serial port you're using and at the same baud rate, and you should be good to go - data sent by one will be received by the serial port of the other. If they're both running an Arduino sketch, you'd be sending data with Serial1.print() (or whatever serial port you're using), and checking for received characters with Serial1.available() and reading them out with Serial1.read().


// Example 1 - Receiving single characters

char receivedChar;
boolean newData = false;

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel

void setup() {
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("");
}

void loop() {
recvOneChar();
showNewData();
}

void recvOneChar() {
if (Serial1.available() > 0) {
receivedChar = Serial1.read();
lcd.print(receivedChar);
newData = true;
}
}

void showNewData() {
if (newData == true) {
Serial.print("This just in … ");
Serial.println(receivedChar);
lcd.setCursor(10,1);
newData = false;
}
}

this is my Arduino skatch.

and this is my codevison code in c for the atmega32 board.

#include <mega32a.h>
#include <io.h>
//header to enable data flow control over pins
#define F_CPU 8000000UL
//telling controller crystal frequency attached
#include <delay.h>
//header to enable delay function in program
int UBBRValue = 6;//AS described before setting baud rate (9600)
void main(void)
{
                DDRD =0b11111110;// 1 << PIND1;//pin1 of portD as OUTPUT
                DDRA =0b00000000;// ~(1 << PIND0);//pin0 of portD as INPUT
                PORTC=0b11111111;// 1 << PIND0;
                PORTC=0;
                
 
                //Put the upper part of the baud number here (bits 8 to 11)
                UBRRH = (unsigned char) (UBBRValue >> 8);
 
                //Put the remaining part of the baud number here
                UBRRL = (unsigned char) UBBRValue;
 
                //Enable the receiver and transmitter
                UCSRB = (1 << RXEN) | (1 << TXEN);
 
                //Set 2 stop bits and data bit length is 8-bit
                UCSRC = (1 << USBS) | (3 << UCSZ0);
 
                while (1)
                {
                                if (PINA.0==0)//once button is pressed
                                {
                                               
                                    while (! (UCSRA & (1 << UDRE)) );
                                     {
                                      UDR = 0b11110000;//once transmitter is ready sent eight bit data
                                     }
                                                           
                                               
                                                delay_ms(220);
                                }
                                PORTC.7=~PORTC.7;
                                delay_ms(200);
                    }
                    }  

So my AVR  board only consist of atmega32 and a few Leds.

I did changed the serial0 to serial 1 and conected that to Arduino.This was help full but dont receive any thing.
In the serial monitor I conteniusly receive the message:This just in ...

The fact that you're getting something but aren't seeing the character being printed suggests it thinks it's receiving something, but it's a non-printing character.

Confirm this by either casting the received character to an int and printing that, or by using a serial terminal that doesn't suck (the arduino ide's serial monitor is garbage).

Assuming that's it, suspect failure to connect grounds or baud rate mismatch. The latter can be caused by wrong clock setting (leading to it not running at the speed you're compiling for) or using the internal oscillator, which is not accurate enough for serial communication without user calibration (factory cal is only to w/in 10%, serial needs 2)

Sorry, but it would take a me a long time to figure out the code you have posted for the Atmega32 board and I am lazy.

Why not also program that board with the Arduino IDE?

...R

DrAzzy:
Assuming that's it, suspect failure to connect grounds or baud rate mismatch. The latter can be caused by wrong clock setting (leading to it not running at the speed you're compiling for) or using the internal oscillator, which is not accurate enough for serial communication without user calibration (factory cal is only to w/in 10%, serial needs 2)

I think you are write! my avr board is running on internal clock(8Mhz).But that I am not going to change for now.
On the other hand I am not getting garbage ,but nothing at all.So don,t you think there may be other problem?

DrAzzy:
Assuming that’s it, suspect failure to connect grounds or baud rate mismatch. The latter can be caused by wrong clock setting (leading to it not running at the speed you’re compiling for) or using the internal oscillator, which is not accurate enough for serial communication without user calibration (factory cal is only to w/in 10%, serial needs 2)

I think you are write! my avr board is running on internal clock(8Mhz).But that I am not going to change for now.
On the other hand I am not getting garbage ,but nothing at all.So don,t you think there may be other problem?

Robin2:
Sorry, but it would take a me a long time to figure out the code you have posted for the Atmega32 board and I am lazy.

Why not also program that board with the Arduino IDE?

.
That may be a good idea but How do I do that ?I have the programer and the isp serial input ,but in the IDE menu for choosing the board and the programmer I don;t know which to choose.

"Why not also program that board with the Arduino IDE?"

How should I program the codes which is written with codevision compiler , to Arduino IDE?

Lets put it this way:

In order to expand the ports of a board already made with atmega32, I want to use an arduino nano or some other types. The original program is working ok in the old board wich is written in codevisin IDE,
now I want to expand the ports by adding an Arduino board to this board,
What is the softwear to write in codevison and in arduino enviroment?