Split from: 1Mhz USART0 on ATtiny841 not working

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

* Split from the 4 year old thread https://www.avrfreaks.net/comment...

 

I am using attiny841 controller for my application. I am facing some strange problem in Uart communication in two controllers. i have same set of hardware and i am using same piece of firmware for both the controllers. Here is my uart initialization function.

void Uart initialization(unsigned int baudrate)

{

UBRR0H = (unsigned char) (baudrate>>8);

UBRR0L = (unsigned char) (baudrate);

UCSR0B |= (1<<RXCIE0);

UCSR0B |= ((1<<RXEN0) | (1<<TXEN0)); //enable receiver and transmitter pin

UCSR0C |= ((1<<UCSZ01) | (1<<UCSZ00)); // setting to 8bit mode

UCSR0B &=~ (1<<UCSZ02);

UCSR0C &=~((1<<UPM00) | (1<<UPM01));

UCSR0C |= (1<<USBS0);

UCSR0A |= (1<< U2X0);

}

 

For one controller, I am able to communicate correctly with  Uart initialization(7); where as for other, it is working with  Uart initialization(8); which means i need to set different baud rate register for 2 different controllers. If i set both to Uart initialization(7); or Uart initialization(8); then i get junk characters in the other.

Please suggest some solution to the issue.

prakash

Last Edited: Wed. Feb 21, 2018 - 11:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to properly post source code: https://www.avrfreaks.net/comment...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

prakashmsd wrote:
For one controller, I am able to communicate correctly with  Uart initialization(7); where as for other, it is working with  Uart initialization(8); which means i need to set different baud rate register for 2 different controllers.

Sounds like you need to do the basic test to find exactly what speeds your two chips are actually running at.

 

Clearly, if they are running at significantly different speeds, then you are bound to need different setting to achieve the same baud rate!

 

EDIT

 

Note that this was already suggested in the 4-year-old thread you originally hijacked: https://www.avrfreaks.net/comment...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Feb 21, 2018 - 11:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 I am using 8 MHz internal clock frequency for both attiny841 controller and two controllers are running at same clock speed. Even though it runs at same clock speed ,it is working at different baud rate. I need to make that controllers working at same baud rate.

prakash

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

prakashmsd wrote:
two controllers are running at same clock speed. Even though it runs at same clock speed 

did you not read #3 ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

prakashmsd wrote:

For one controller, I am able to communicate correctly with  Uart initialization(7); where as for other, it is working with  Uart initialization(8); which means i need to set different baud rate register for 2 different controllers. If i set both to Uart initialization(7); or Uart initialization(8); then i get junk characters in the other.

Please suggest some solution to the issue.

I don't think the Uart initialization function has anything to do with the problem.  Show us all of the Uart code and we might be able to help you.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

prakashmsd wrote:
I am using 8 MHz internal clock frequency for both attiny841 controller

 

How many threads have been posted here asking about using the internal RC and serial comm problems......

Too many!

The simple answer is add a xtal and two caps and set the fuses to use same and your serial comms will work as expected, because Async comms require an accurate and stable clock source to be reliable and consistant!

 

Jim

 

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274