Skip to main content
fixed tabulation
Source Link
Bence Kaulics
  • 6.4k
  • 12
  • 35
  • 60
            //tx serial
 
            #include <avr/io.h> 

            #define F_CPU 16000000 
            #define BUAD 9600 
            #define BUAD_RATE_CALC ((F_CPU/16/BUAD) - 1)  


            int main(void){  
               
                char ar[]= "hello";
                 
                //High and low bits
                UBRR0H = (BUAD_RATE_CALC >> 8); 
                UBRR0L = BUAD_RATE_CALC; 
                //////////////// 
                //transimit and recieve enable
                UCSR0B = (1 << TXEN0)| (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0); 
                UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);  //8 bit data format
                ////////////////////////////////////////////////////////////////
                int i = 0;
                
                while (1){  
               
                while (( UCSR0A & (1<<UDRE0))  == 0){};
                    for (i = 0; i < strlen(ar); i++){ 
                        UDR0 = ar[i]; 
                    }
                    

                }
 
            }  
            //tx serial
 
            #include <avr/io.h> 

            #define F_CPU 16000000 
            #define BUAD 9600 
            #define BUAD_RATE_CALC ((F_CPU/16/BUAD) - 1)  


            int main(void){  
               
                char ar[]= "hello";
                 
                //High and low bits
                UBRR0H = (BUAD_RATE_CALC >> 8); 
                UBRR0L = BUAD_RATE_CALC; 
                //////////////// 
                //transimit and recieve enable
                UCSR0B = (1 << TXEN0)| (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0); 
                UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);  //8 bit data format
                ////////////////////////////////////////////////////////////////
                int i = 0;
                
                while (1){  
               
                while (( UCSR0A & (1<<UDRE0))  == 0){};
                    for (i = 0; i < strlen(ar); i++){ 
                        UDR0 = ar[i]; 
                    }
                    

                }
 
            }  
//tx serial
#include <avr/io.h> 

#define F_CPU 16000000 
#define BUAD 9600 
#define BUAD_RATE_CALC ((F_CPU/16/BUAD) - 1)  


int main(void){  
   
    char ar[]= "hello";
     
    //High and low bits
    UBRR0H = (BUAD_RATE_CALC >> 8); 
    UBRR0L = BUAD_RATE_CALC; 
    //////////////// 
    //transimit and recieve enable
    UCSR0B = (1 << TXEN0)| (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0); 
    UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);  //8 bit data format
    ////////////////////////////////////////////////////////////////
    int i = 0;
    
    while (1){  
   
    while (( UCSR0A & (1<<UDRE0))  == 0){};
        for (i = 0; i < strlen(ar); i++){ 
            UDR0 = ar[i]; 
        }
    }
}
Source Link
Redrachet2
  • 77
  • 2
  • 5
  • 15

How to send string in serial communication in AVR-C

So as the title states, instead of sending a byte of information at a time, I would like to be able to send a whole string. What I tried to do was that I tried to put the user input in an array and get each element of that array to be transmitted. However I was only able to get the first few letters to transmit not the whole array, here is my code:

            //tx serial

            #include <avr/io.h> 

            #define F_CPU 16000000 
            #define BUAD 9600 
            #define BUAD_RATE_CALC ((F_CPU/16/BUAD) - 1)  


            int main(void){  
               
                char ar[]= "hello";
                 
                //High and low bits
                UBRR0H = (BUAD_RATE_CALC >> 8); 
                UBRR0L = BUAD_RATE_CALC; 
                //////////////// 
                //transimit and recieve enable
                UCSR0B = (1 << TXEN0)| (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0); 
                UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);  //8 bit data format
                ////////////////////////////////////////////////////////////////
                int i = 0;
                
                while (1){  
               
                while (( UCSR0A & (1<<UDRE0))  == 0){};
                    for (i = 0; i < strlen(ar); i++){ 
                        UDR0 = ar[i]; 
                    }
                    

                }

            }  

What would the problem be with this?