Not able to get proper data from USART0

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

Hello

Currently i am working on ATtiny424 microcontroller, I am facing issue while writing data on USART0.

Configuration which i have done using Atmel start online tool attached, Also printf statement is not work.

 

Here i am sharing simple code please have look

 

#include <atmel_start.h>
#include "driver_init.h"
#include <util/delay.h>
#include <atomic.h>
#include <stdio.h>

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();

    /* Replace with your application code */
    while (1) {
        USART_0_write('A');
        printf("Hello\n");
        _delay_ms(1000);    
    }
    return 0;
}

 

  • Also attached output of above code, in which i get garbage value, please have look and let me know if any have solution of this issue.

 

       

Attachment(s): 

This topic has a solution.

Thanks & Regard
Rajendrasinh Chhasatiya

Last Edited: Thu. Jun 30, 2022 - 08:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Is the AVR actually set for 1 MHZ?

 

Also, start with 9600 baud, things are much less critical, such as timings, electrical wires, ristimes, etc.  If it won't work at 9600 , it won't at faster speeds.  Of course make sure your gnd wire is hooked up from the terminal to the AVR.

And TX to RX, and RX to TX

 

Is the clock source accurate enough?  I didn't check the '424, but many internal clocks are  borderline (newer chip are better).

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Wed. Jun 29, 2022 - 05:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello  avrcandie,

Thanks for the reply.

 

  • yes, the AVR actually set for 1 MHz, also GND, Tx, Rx wires are hooked up from terminal to the ATtiny.
  • Currently i am using internal clock, and ATtiny424 support 20 MHz as mention in datasheet, but the problem is that when i set Clock greater than 2 MHz, my controller got damaged.
  • Also will try using 9600 baud, and let you know the result for the same.  

 

Thanks & Regard
Rajendrasinh Chhasatiya

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If your project involves UART was has led you to choose 1Mhz as the clock speed ?

 

Note also that tiny424 has a 20MHz clock and by default that is divided by 6 to run at 3.3Mhz so where in the code is that being adjusted to 1MHz anyway? Is that something happening inside atmel_start_init() ?

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

The minimum BAUD register value is 64 since this usart uses a fractional baud rate generator. At 115200 with a 1MHz clock, your baud register value calculates to 35 which is too low (effectively 0). You can set CTRLB.RXMODE to CLK2X which will then get your baud value above 64 in this case (also calculate value for clk2x). The atmel start code does no checking to see if the baud value wanted will result in a valid value, and it seems they do not allow you to configure the rxmode until you switch to an 'Init' driver mode instead of 'Basic'. In any case it looks like you are in charge of determining whether the baud register value will be >= 64.

 

Simple example with no atmel start-

https://godbolt.org/z/xjfe754n6

Last Edited: Wed. Jun 29, 2022 - 08:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hello all,

 

Thanks for your valuable time,  I've little modified UART configurations change clock frequency to 3.3MHz and it now it works perfectly.

Thank you for all for help.smiley

Thanks & Regard
Rajendrasinh Chhasatiya