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:
And the terminal settings:
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;
}