1

I'm trying to write a program in C that takes a character input from the user, saves it to a variable and then and transmits it to the Serial Port.

I'm using a Romeo Board, Atmega328p and an Arduino Serial Monitor. I know the board/serial monitor work because I'm able to transmit. I just can't get input/receive side of things working.

Here's my code:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>


 int main(void){

    initUART(9600);


    while(1){

        unsigned char beta = receiveByte();
        transmitByte(beta);

        _delay_ms(1500);


    }
 }


 void initUART(unsigned int baud) {
   unsigned int ubrr = F_CPU/16/baud-1;  //Normal mode UBRR formula

   UBRR0H = (unsigned char) (ubrr >> 8); 
   UBRR0L = (unsigned char) ubrr;  

   UCSR0B = (1 << RXEN0) | (1 << TXEN0);  
   UCSR0C = (1 <<UCSZ00) | (1 <<UCSZ01);  
 }

 unsigned char receiveByte (void) {
   while ( !(UCSR0A &  (1 << RXC0)) );    
   return UDR0;  
 } 

I know about Serial.read() but can't use it as it's outside the bounds of my lab (which is actually more complicated then this)

Any tips or leads would be appreciated.

0 Answers0