Hello everyone!
I came across an unusual behavior of the USART - the data sent to the Atmega8 (via pty serial interface)is distorted. for example, data from 0x00 to 0x19 comes correctly, and everything above 0x19 already comes to the MC in the form of two bytes. Here is my diagram, can someone help me figure it out (its simple echo), thank you ?
My setup:
6.1.14-200.fc37.x86_64
SimulIDE 1.0.0-SR0 t Rev 1320
main.c:
pty:
event:
I came across an unusual behavior of the USART - the data sent to the Atmega8 (via pty serial interface)is distorted. for example, data from 0x00 to 0x19 comes correctly, and everything above 0x19 already comes to the MC in the form of two bytes. Here is my diagram, can someone help me figure it out (its simple echo), thank you ?
My setup:
6.1.14-200.fc37.x86_64
SimulIDE 1.0.0-SR0 t Rev 1320
main.c:
- Code:
// ATMEGA8-16PU USART echo
#define F_CPU 16000000UL
#define __AVR_ATmega8__
#include <avr/io.h>
#include <stdint.h>
#include <util/delay.h>
#define BAUD 1000000
#define BAUDRATE ((F_CPU + (BAUD * 4)) / (BAUD * - 1) // U2X == 1
void usart_init(unsigned int ubrr) {
UBRRH = (ubrr >> 8);
UBRRL = ubrr;
UCSRB = (1 << TXEN) | (1 << RXEN); // enable receiver and transmitter
UCSRA = (1 << U2X); // enable 2x mode
UCSRC = (1 << UCSZ0) | (1 << UCSZ1) | (1 << USBS); // 8bit 2stop data format
}
int main() {
usart_init(BAUDRATE);
DDRB = 0b11111111; // set all PortC Output
DDRC = 0b11111111; // set all PortC Output
DDRD = 0b11111111; // set all PortC Output
unsigned char tmp;
while (1) {
while (!(UCSRA & (1 << RXC)))
;
tmp = UDR;
while (!(UCSRA & (1 << UDRE)))
;
UDR = tmp;
}
}
pty:
- Code:
socat -d -d pty,rawer,echo=0,link=pty_in,user=LINUX_USERNAME_HERE pty,rawer,echo=0,link=pty_out,user=LINUX_USERNAME_HERE
event:
- Code:
watch -n 1 'echo -n "1">pty_in'