Pages: [1]   Go Down
Author Topic: ATMega168 vs 328 USART -- what's different?  (Read 1059 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on a DMX receiver circuit that I originally developed for the ATMega168 chip (I'm using bare chips and my own boards).  When I reordered more chips I got the ATMega328 instead, thinking that the only difference was more memory.  My problem is that the ATMega168 chip works and the ATMega328 chip doesn't, even though I'm uploading the same sketch and using the same board.

The ATMega168 will properly receive the DMX signal coming in on the RX pin (via an SN75176).  The ATMega328, however, freezes when it sees anything on the RX pin.  Is there something different about the USART on the 328?

I'll keep browsing through the forum here, but if anyone can help me figure out what's different between the 168 and 328 I'd love to hear from you.  I'm currently using Arduino-0018 on Xubuntu Linux.


Jeremy
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using DMX code based on this thread (post #20):
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1223117506/15


Jeremy
Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you change the Board setting to a 328 in the IDE?
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I got an upload error message if I didn't.

For the ATMega328, I used "Arduino Duemilanove or Nano w/ ATmega328".
For the ATMega168, I used "Arduino Diecimila, Duemilanove, or Nano w/ ATmega168".


Otherwise everything else is the same -- hardware board, parallel programming cable, sketch, etc.


Jeremy
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I think I found the problem.  The name of the interrupt handler needed to be changed from:

SIGNAL(SIG_USART_RECV) {  // for ATMega168
...
}

to:
SIGNAL(USART_RX_vect) {  // for ATMega328
...
}

Ironically both names seem to work fine for the ATMega168.  I realized something was wrong with the interrupt handler routine because the compiled sketch was staying the same size even when I commented out parts of the routine.

Good news is that I did learn a few things about the inner workings of the chip in the process -- little did I know that the full datasheet was 500+ pages long... yikes!  Looks like I've got some more reading to do.


Jeremy
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

While you're at it:

Code:
Deprecated:
    Do not use SIGNAL() in new code. Use ISR() instead.

http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html#g67cd0dea412157775c2f2a3ffe9fb8ff
Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good to know -- I have changed my code to use ISR(), and everything appears to be working great.  Thanks for the tip!


Jeremy
Logged

Pages: [1]   Go Up
Jump to: