Go Down

Topic: ATMega168 vs 328 USART -- what's different? (Read 2260 times) previous topic - next topic


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.



I'm using DMX code based on this thread (post #20):



Did you change the Board setting to a 328 in the IDE?
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter


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.



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

SIGNAL(SIG_USART_RECV) {  // for ATMega168

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.



While you're at it:

Code: [Select]
   Do not use SIGNAL() in new code. Use ISR() instead.

• 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!


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


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131