AVR UART not really working

hello...

 

I'm still developing a code here...

 

can somebody test it out somehow?

 

I don't know what is the problem

 

the reciever or the transmitter

 

 

here is the code for the reciever:

 

 

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
/* PB4 M1    - pwm B
 * PB2 M1
 * PB3 M2    - pwm A
 * PB1 M2
 * PD6 M1    -enable
 * PB0 M2    -enable
 * forward: PB1,PB2 low, pwm
 * reverse: PB1,PB2 high, inverted pwm
 * stop: PB1,PB2 low, pwm 0(low);
 * protocol has to send first the direction, 2. left speed (M2), 3. right speed
 */

void forward(void);
void reverse(void);
void left(void);
void right(void);
void stop(void);
void USART_init(uint16_t ubrr_value);

uint8_t direction; //0-stop, 1-forward, 2-reverse, 3 - left, 4 - right
char getspeed = 'n';
uint8_t EEMEM speedL = 150;
uint8_t EEMEM speedR = 150;

int main()
    {
    DDRB = 0xFF; //motors output
    DDRD |= (1 << PD6); //motor output
    PORTD |= (1 << PD6); //enable 1
    PORTB |= (1 << PB0); //enable 2
    TCCR1B |= (1 << CS10);
    USART_init(25); //9600 baud
    direction = 0;
    sei();
    while (1)
    {
    switch (direction)
        {
    case 0:
        stop();
        break;
    case 1:
        forward();
        break;
    case 2:
        reverse();
        break;
    case 3:
        left();
        break;
    case 4:
        right();
        break;
        }
    }
    };

void reverse()
    {
    PORTB = 0b00000101;
    TCCR1A = 0b10110001;
    };

void forward()
    {
    PORTB = 0b00000011;
    TCCR1A = 0b11010001;
    };

void right()
    {
    PORTB = 0b00000111;
    TCCR1A = 0b11110001;
    };

void left()
    {
    PORTB = 0b00000001;
    TCCR1A = 0b10100001;
    };

void stop()
    {
    OCR1A = 0;
    OCR1B = 0;
    };

//UART PART
void USART_init(uint16_t ubrr_value)
    {
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value >> 8);

    UCSRC = (1 << UCSZ1) | (1 << UCSZ0);
    UCSRB = (1 << RXEN)|(1<<RXCIE);
    };

ISR(USART_RX_vect)
    {
    char info;
    while (!(UCSRA & (1 << RXC)));
    info = UDR;
    if (info == 'y')
    {
    while (!(UCSRA & (1 << RXC)));
    direction = UDR;
    if (!(direction == 0))
        {
        while (!(UCSRA & (1 << RXC)));
        OCR1A = UDR;
        while (!(UCSRA & (1 << RXC)));
        OCR1B = UDR;
        }
    else
        {
        OCR1A = 0;
        OCR1B = 0;
        }
    }
    else
    {
    while (!(UCSRA & (1 << RXC)));
    direction = UDR;
    OCR1A = eeprom_read_byte(&speedL);
    OCR1B = eeprom_read_byte(&speedR);
    }

    };

 

if there is a problem here please let me know...

 

Thank you

Um, really? You’re not

Um, really? You’re not really giving much to go by…but for S&G here are some questions…

How have you been testing this? What are you using to debug this? What do you suspect is the problem?

What setup are you using, internal resonator, external res, crystal?

What is this connected to? Are you using a wireless device?

 

two MCUs via simple

two MCUs via simple wires:

Tx1 -> Rx2

Rx1 <- Tx2tern

 

external crystal 4.000 mhz, internal 8 divider off

 

transmitter Mcu internal calibrated resonator, 4 mhz, clock divider off

transmitter

transmitter MCU

 

 

 

#include <avr/io.h>
#include <util/delay.h>
void start(uint16_t ubrr_value);
void send(unsigned char data);

int main()
    {
    int forw = 1;
    int rev = 2;
    int left = 3;
    int right = 4;
    int stop = 0;
    int speedleft = 128;
    int speedright = 128;
    start(25);

    while (1)
    {
    send(forw);
    send(speedleft);
    send(speedright);
    _delay_ms(2000);
    send(rev);
    send(speedleft);
    send(speedright);
    _delay_ms(2000);
    }
    }
;

void start(uint16_t ubrr_value)
    {
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value >> 8);

    UCSRC = (1 << UCSZ1) | (1 << UCSZ0); //8bit 1 stop bit
    UCSRB = (1 << TXEN); //interrupt enable
    }
;

void send(unsigned char data)
    {
    /* Wait for empty transmit buffer /
    while (!(UCSRA & (1 << UDRE)))
    ;
    /
Put data into buffer, sends the data */
    UDR = data;
    }
;