Pages: [1]   Go Down
Author Topic: Serial not working on stand-alone 328-p  (Read 867 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to get my senior design project working. I'm using an ARM to control a quadrotor. The arm doesn't want to talk i2c for some reason, so I'm trying to use a atmega328 I have around as an interperter to serial. Another team member wrote working code to talk to the IMU sensor using the wire library on his arduino uno. I go to drop the same code (with a very slight modification in some serial writes) and nothing. I have the chip set up to run of the internal oscillator. I use a USB Tiny to flash, and have an Omliex dev board. I changed the F_CPU setting to 8000000L in the board.txt file. I'm not using a bootloader. I have no idea why I get no serial out. I even wrote a small test program that all it should do is echo any serial it gets back.
Code:
void setup() {
Serial.begin(9600);
Serial.write("Ready\n");

}

void loop() {
if(Serial.available() > 0) Serial.write(Serial.read()); 
}

I am not new to AVR, but I've never worked with the Arduino stuff before, so any thoughts on why this isn't working is appreciated
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
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

Try breaking this up some, or changing Serial.write to Serial.print

if(Serial.available() > 0) {
  byte incomingByte =  Serial.read();
  Serial.print(incomingByte);
}
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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
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

Serial.write may result in unprintable data being sent out. From the Reference page for Serial:

write()
Description
Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead.

print()
Description
Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is.
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.

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

Thanks for the reply. I don't think that's the issue, though. I don't even get that Ready printed in the terminal when I fire up the avr. Like I said, that's just a test program and I was only sending ascii values to it. I also set my terminal (using GTKTerm) to print hex values so I could check the data rather than printable characters. I'm just not getting data period.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
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 have Gnd connected between devices? Any chance Rx & Tx are swapped in your cabling?
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.

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

I'm sure ground is good. I can jump the pins on the socket for the AVR with a wire and see an echo, so that's good. I just borrowed a friend's arduino and tested the code on it. Code works fine, so this is definitely something to do with me trying to load it to a non-arduinoified (is that how to say it?) AVR. I would think it should just work.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
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

Did you program the fuses on your standalone device? Need an AVR programmer connected to the SPI pins & Reset, +5, Gnd to do that.
The default fuse settings may be messing you up - resulting in a 1 MHz clock speed.
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.

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

Programing the fuses to remove the prescaler was the first thing I did. I will double check later that they are correct. Its starting to look like I may have a bad sensor, so I may not need this anyway, but I would like to figure out why its not playing nice regardless.
Logged

Pages: [1]   Go Up
Jump to: