Quantcast
Channel: Question and Answer » uart
Viewing all articles
Browse latest Browse all 57

Getting [VTERM] Parity Error when simulating USART connection in proteus

$
0
0

I’m trying to simulate USART connection between atmega32 and a virtual terminal.
But when I push the button to start the transmission, I always get

[VTERM] Parity Error

I’ve set even parity from the code and set the virtual terminal to have even parity as well.

Here’s the circuit:

enter image description here

And the terminal settings:

enter image description here

Here’s my code:

#include <avr/io.h>

void init();
void transmit(unsigned char);
unsigned char recieve();

int main(void)
{
    DDRA &= ~(1 << PA0);
    init();
    while (1) 
    {
        if(PINA & (1 << PA0)){
            transmit('a');
            while(PINA & (1 << PA0)){}
        }
    }
}

void init()
{
    //Set baud
    UBRRH = (unsigned char) (6 >> 8);
    UBRRL = (unsigned char) 6;

    //Enable TX & RX
    UCSRB |= (1 << TXEN) | (1 << RXEN);

    //Set parity EVEN
    UCSRC = (1 << URSEL) | (1 << UPM1);

    //Set stop bits (2 bits)
    UCSRC |= (1 << USBS);

    //Set data size 8bit
    UCSRC |= (1 << UCSZ0) | (1 << UCSZ1);
}

void transmit(unsigned char data)
{
    while(! (UCSRA & (1 << UDRE))){}
    UCSRB &= ~(1 << TXB8);
    if(data & 0x0100) {
        UCSRB |= (1 << TXB8);
    }
    UDR = data;
}

Viewing all articles
Browse latest Browse all 57

Trending Articles