Atmega168 USART transmitter with interrupts












0















I try to transmit data from my Atmega168A-PU to my computer using the USART.
To do so I have written the following code:



#include <avr/io.h>
#include <stdlib.h>

#define F_CPU 8000000UL
#define USART_BAUD 9600
#define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

void
usart_init(void)
{
UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
UBRR0L = (unsigned char)UBRR_VALUE;
UCSR0B = _BV(TXEN0) | _BV(UDRIE0);
UCSR0C = _BV(USBS0) | _BV(UCSZ00) | _BV(UCSZ01);
//UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
}


ISR(USART0_UDRE_vect)
{
UDR0 = '0';
UCSR0A |= _BV(TXC0);
}

int main(void)
{
usart_init();
while(!(UCSR0A & _BV(UDRE0)));
UDR0 = '0';
while(1);
return 0;
}


I have attached the Arduino USB2SERIAL converter to read the values on my computer, however the converter says that he does not receive data and my computer does not receive data either.



Note: My lfuse is 0xe2 (CLKDIV8 disabled), so I have 8MHz F_CPU.

Note: I tried without the UCSR0A |= _BV(TXC0);, too.

Note: I have a capacitor between AVcc and AGnd.

Note: Fuses: (E:F9, H:DF, L:E2)










share|improve this question























  • Maybe you are going to miss that one byte sent in the main. The UDRE ISR should be firing as fast as it can send that byte, but it the global ISR flag have to be actually enabled.

    – KIIV
    Jan 1 at 19:54
















0















I try to transmit data from my Atmega168A-PU to my computer using the USART.
To do so I have written the following code:



#include <avr/io.h>
#include <stdlib.h>

#define F_CPU 8000000UL
#define USART_BAUD 9600
#define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

void
usart_init(void)
{
UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
UBRR0L = (unsigned char)UBRR_VALUE;
UCSR0B = _BV(TXEN0) | _BV(UDRIE0);
UCSR0C = _BV(USBS0) | _BV(UCSZ00) | _BV(UCSZ01);
//UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
}


ISR(USART0_UDRE_vect)
{
UDR0 = '0';
UCSR0A |= _BV(TXC0);
}

int main(void)
{
usart_init();
while(!(UCSR0A & _BV(UDRE0)));
UDR0 = '0';
while(1);
return 0;
}


I have attached the Arduino USB2SERIAL converter to read the values on my computer, however the converter says that he does not receive data and my computer does not receive data either.



Note: My lfuse is 0xe2 (CLKDIV8 disabled), so I have 8MHz F_CPU.

Note: I tried without the UCSR0A |= _BV(TXC0);, too.

Note: I have a capacitor between AVcc and AGnd.

Note: Fuses: (E:F9, H:DF, L:E2)










share|improve this question























  • Maybe you are going to miss that one byte sent in the main. The UDRE ISR should be firing as fast as it can send that byte, but it the global ISR flag have to be actually enabled.

    – KIIV
    Jan 1 at 19:54














0












0








0








I try to transmit data from my Atmega168A-PU to my computer using the USART.
To do so I have written the following code:



#include <avr/io.h>
#include <stdlib.h>

#define F_CPU 8000000UL
#define USART_BAUD 9600
#define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

void
usart_init(void)
{
UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
UBRR0L = (unsigned char)UBRR_VALUE;
UCSR0B = _BV(TXEN0) | _BV(UDRIE0);
UCSR0C = _BV(USBS0) | _BV(UCSZ00) | _BV(UCSZ01);
//UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
}


ISR(USART0_UDRE_vect)
{
UDR0 = '0';
UCSR0A |= _BV(TXC0);
}

int main(void)
{
usart_init();
while(!(UCSR0A & _BV(UDRE0)));
UDR0 = '0';
while(1);
return 0;
}


I have attached the Arduino USB2SERIAL converter to read the values on my computer, however the converter says that he does not receive data and my computer does not receive data either.



Note: My lfuse is 0xe2 (CLKDIV8 disabled), so I have 8MHz F_CPU.

Note: I tried without the UCSR0A |= _BV(TXC0);, too.

Note: I have a capacitor between AVcc and AGnd.

Note: Fuses: (E:F9, H:DF, L:E2)










share|improve this question














I try to transmit data from my Atmega168A-PU to my computer using the USART.
To do so I have written the following code:



#include <avr/io.h>
#include <stdlib.h>

#define F_CPU 8000000UL
#define USART_BAUD 9600
#define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

void
usart_init(void)
{
UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
UBRR0L = (unsigned char)UBRR_VALUE;
UCSR0B = _BV(TXEN0) | _BV(UDRIE0);
UCSR0C = _BV(USBS0) | _BV(UCSZ00) | _BV(UCSZ01);
//UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
}


ISR(USART0_UDRE_vect)
{
UDR0 = '0';
UCSR0A |= _BV(TXC0);
}

int main(void)
{
usart_init();
while(!(UCSR0A & _BV(UDRE0)));
UDR0 = '0';
while(1);
return 0;
}


I have attached the Arduino USB2SERIAL converter to read the values on my computer, however the converter says that he does not receive data and my computer does not receive data either.



Note: My lfuse is 0xe2 (CLKDIV8 disabled), so I have 8MHz F_CPU.

Note: I tried without the UCSR0A |= _BV(TXC0);, too.

Note: I have a capacitor between AVcc and AGnd.

Note: Fuses: (E:F9, H:DF, L:E2)







avr atmega usart






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 17:09









LittleByBlueLittleByBlue

314415




314415













  • Maybe you are going to miss that one byte sent in the main. The UDRE ISR should be firing as fast as it can send that byte, but it the global ISR flag have to be actually enabled.

    – KIIV
    Jan 1 at 19:54



















  • Maybe you are going to miss that one byte sent in the main. The UDRE ISR should be firing as fast as it can send that byte, but it the global ISR flag have to be actually enabled.

    – KIIV
    Jan 1 at 19:54

















Maybe you are going to miss that one byte sent in the main. The UDRE ISR should be firing as fast as it can send that byte, but it the global ISR flag have to be actually enabled.

– KIIV
Jan 1 at 19:54





Maybe you are going to miss that one byte sent in the main. The UDRE ISR should be firing as fast as it can send that byte, but it the global ISR flag have to be actually enabled.

– KIIV
Jan 1 at 19:54












1 Answer
1






active

oldest

votes


















0














Well the problem was pretty easy. I forgot the sei(); as @KIIV pointed out (also u/odokemono pointed that out). Thanks.



Also it is better to use the USART_TX_vect instead of USART0_UDRE_vect because my receiver is disabled. Here is the corrected code:



#include <avr/io.h>
#include <stdlib.h>
#include <avr/interrupt.h>

#define F_CPU 8000000UL
#define USART_BAUD 9600
#define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

void
usart_init(void)
{
UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
UBRR0L = (unsigned char)UBRR_VALUE;
UCSR0B = _BV(TXEN0) | _BV(TXCIE0);
UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
//UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
sei();
}


ISR(USART_TX_vect)
{
UDR0 = '0';
UCSR0A |= _BV(TXC0);
}

int main(void)
{
usart_init();
while(!(UCSR0A & _BV(UDRE0)));
UDR0 = '0';
while(1);
return 0;
}


By the way: I disabled the second stop bit as u/odokemono pointed out because my USB2SERIAL seems to work better without the second stop bit.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997365%2fatmega168-usart-transmitter-with-interrupts%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Well the problem was pretty easy. I forgot the sei(); as @KIIV pointed out (also u/odokemono pointed that out). Thanks.



    Also it is better to use the USART_TX_vect instead of USART0_UDRE_vect because my receiver is disabled. Here is the corrected code:



    #include <avr/io.h>
    #include <stdlib.h>
    #include <avr/interrupt.h>

    #define F_CPU 8000000UL
    #define USART_BAUD 9600
    #define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

    void
    usart_init(void)
    {
    UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
    UBRR0L = (unsigned char)UBRR_VALUE;
    UCSR0B = _BV(TXEN0) | _BV(TXCIE0);
    UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
    //UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
    sei();
    }


    ISR(USART_TX_vect)
    {
    UDR0 = '0';
    UCSR0A |= _BV(TXC0);
    }

    int main(void)
    {
    usart_init();
    while(!(UCSR0A & _BV(UDRE0)));
    UDR0 = '0';
    while(1);
    return 0;
    }


    By the way: I disabled the second stop bit as u/odokemono pointed out because my USB2SERIAL seems to work better without the second stop bit.






    share|improve this answer




























      0














      Well the problem was pretty easy. I forgot the sei(); as @KIIV pointed out (also u/odokemono pointed that out). Thanks.



      Also it is better to use the USART_TX_vect instead of USART0_UDRE_vect because my receiver is disabled. Here is the corrected code:



      #include <avr/io.h>
      #include <stdlib.h>
      #include <avr/interrupt.h>

      #define F_CPU 8000000UL
      #define USART_BAUD 9600
      #define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

      void
      usart_init(void)
      {
      UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
      UBRR0L = (unsigned char)UBRR_VALUE;
      UCSR0B = _BV(TXEN0) | _BV(TXCIE0);
      UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
      //UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
      sei();
      }


      ISR(USART_TX_vect)
      {
      UDR0 = '0';
      UCSR0A |= _BV(TXC0);
      }

      int main(void)
      {
      usart_init();
      while(!(UCSR0A & _BV(UDRE0)));
      UDR0 = '0';
      while(1);
      return 0;
      }


      By the way: I disabled the second stop bit as u/odokemono pointed out because my USB2SERIAL seems to work better without the second stop bit.






      share|improve this answer


























        0












        0








        0







        Well the problem was pretty easy. I forgot the sei(); as @KIIV pointed out (also u/odokemono pointed that out). Thanks.



        Also it is better to use the USART_TX_vect instead of USART0_UDRE_vect because my receiver is disabled. Here is the corrected code:



        #include <avr/io.h>
        #include <stdlib.h>
        #include <avr/interrupt.h>

        #define F_CPU 8000000UL
        #define USART_BAUD 9600
        #define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

        void
        usart_init(void)
        {
        UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
        UBRR0L = (unsigned char)UBRR_VALUE;
        UCSR0B = _BV(TXEN0) | _BV(TXCIE0);
        UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
        //UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
        sei();
        }


        ISR(USART_TX_vect)
        {
        UDR0 = '0';
        UCSR0A |= _BV(TXC0);
        }

        int main(void)
        {
        usart_init();
        while(!(UCSR0A & _BV(UDRE0)));
        UDR0 = '0';
        while(1);
        return 0;
        }


        By the way: I disabled the second stop bit as u/odokemono pointed out because my USB2SERIAL seems to work better without the second stop bit.






        share|improve this answer













        Well the problem was pretty easy. I forgot the sei(); as @KIIV pointed out (also u/odokemono pointed that out). Thanks.



        Also it is better to use the USART_TX_vect instead of USART0_UDRE_vect because my receiver is disabled. Here is the corrected code:



        #include <avr/io.h>
        #include <stdlib.h>
        #include <avr/interrupt.h>

        #define F_CPU 8000000UL
        #define USART_BAUD 9600
        #define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)

        void
        usart_init(void)
        {
        UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
        UBRR0L = (unsigned char)UBRR_VALUE;
        UCSR0B = _BV(TXEN0) | _BV(TXCIE0);
        UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
        //UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
        sei();
        }


        ISR(USART_TX_vect)
        {
        UDR0 = '0';
        UCSR0A |= _BV(TXC0);
        }

        int main(void)
        {
        usart_init();
        while(!(UCSR0A & _BV(UDRE0)));
        UDR0 = '0';
        while(1);
        return 0;
        }


        By the way: I disabled the second stop bit as u/odokemono pointed out because my USB2SERIAL seems to work better without the second stop bit.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 22:40









        LittleByBlueLittleByBlue

        314415




        314415
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997365%2fatmega168-usart-transmitter-with-interrupts%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith