I have an Arduino Mega and I wanted to dive in and see how everything really works by following this tutorial with an Atmega644 and a usbASP programmer. After blinking an LED, I felt the next logical step would be to communicate some bytes over a serial connection with the Arduino. Unfortunately, regardless of what I do the Arduino only receives a random combination of 0 and 128 values.
Things I've tried:
- Reading the serial data transmitted from the Atmega644 with the second Serial connection(since I have a Mega), and then with the SoftwareSerial library(on the 10 and 11 pins)
- Changing the baud rate with no effect on the random 0 and 180 values
- Confirmed that the timing is set correctly and is 16Mhz with a LED flashing program at 1 second intervals.
This is a cut down version of the program on the Atmega644 that sends bytes, but I have tried about 6 other programs provided in serial communication tutorials with no noticeable effect:
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#define F_CPU 16000000
#define BAUD 9600
#include <util/setbaud.h>
void uart_init(void) {
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= _BV(U2X0);
#else
UCSR0A &= ~(_BV(U2X0));
#endif
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
}
void uart_putchar(char c) {
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
}
int main(void) {
uart_init();
for(;;;)
uart_putchar('A');//I've also tried sending incremental values to try and affect the random output
return 0;
}
Arduino sketch:
#include <SoftwareSerial.h>
SoftwareSerial portOne(10,11);
void setup()
{
Serial.begin(9600);
portOne.begin(9600);
}
void loop()
{
portOne.listen();
while (portOne.available() > 0) {
Serial.println("Data from port one:");
unsigned char inByte = portOne.read();
Serial.print(inByte);
Serial.println();
}
}
At this point I'm fairly positive that I've just configured something wrong but I've exhausted every possibility I can think of. Could someone shed some light on why I might be only receiving random values of either 0 or 128, even when I change almost every condition possible in the programs? I would try and simplify this by trying to receive the serial data through a usb port but the usbASP sadly doesn't support serial communication from the AVR to the computer.
Thanks in advance