Hallo, ich möchte mit einem Atmega88PA und einem CP2102 USB UART Converter eine Verbindung zu dem H-Terminal herstellen. Von dem Terminal möchte ich ein a zum Kontroller senden und dieser soll es wieder zurücksenden. Aber aus irgend einem Grund klappt das nicht, habe ich den Converter falsch angeschlossen oder bei dem Terminal etwas falsch eingestellt (Bild) ? COM3 stimmt jedenfalls könnte mir bitte jemand weiterhelfen.
1 | /* Funktionen zum Senden und Empfangen eines Bytes im Polling
|
2 | * Ein empfangenes Zeichen wieder senden und am PortB ausgeben * Pinbelegung der UART-Schnittstelle: Tx = PD1, Rx = PD0
|
3 | * Controller: ATmega88 @ 16MHz Quarz extern
|
4 | */
|
5 | #include <avr/io.h> |
6 | |
7 | #define FOSC 16000000 // Set clock Speed in Hz
|
8 | #define BAUD 9600 // Set baud rate
|
9 | #define UBRR_Value FOSC/16/BAUD-1 // Set baud rate value in baud rate register
|
10 | |
11 | void USART_Init( uint16_t ubrr) |
12 | {
|
13 | UBRR0H = (uint8_t)(ubrr >> 8); // Set baud rate in high- and low-register |
14 | UBRR0L = (uint8_t)ubrr; // Set low-register always after high-register |
15 | UCSR0C = (1<<UCSZ01)|(1<<UCSZ00); // Set frame format: 8data, 1stop bit |
16 | UCSR0B = (1<<RXEN0)|(1<<TXEN0); // Enable receiver and transmitter |
17 | }
|
18 | |
19 | void USART_Transmit(uint8_t data) |
20 | {
|
21 | while ( !( UCSR0A & (1<<UDRE0)) ); // Wait for empty transmit buffer |
22 | UDR0 = data; // Put data into buffer, sends the data |
23 | }
|
24 | |
25 | uint8_t USART_Receive(void) |
26 | {
|
27 | while ( !(UCSR0A & (1<<RXC0)) ); // Wait for data to be received |
28 | return UDR0; // Get and return received data from buffer |
29 | }
|
30 | |
31 | /**** Flush Receive-Buffer (entfernen evtl. vorhandener ungültiger Werte) ****/
|
32 | void USART_Flush(void) |
33 | {
|
34 | uint8_t dummy; |
35 | while (UCSR0A & (1<<RXC0)) |
36 | dummy = UDR0; |
37 | }
|
38 | |
39 | int main( void ) |
40 | {
|
41 | uint8_t data; |
42 | USART_Init(UBRR_Value); // Init UART |
43 | USART_Flush(); // Flush Receive-Buffer |
44 | DDRB = 0xFF; // alle PINs an PortB als Ausgänge |
45 | |
46 | while(1) |
47 | {
|
48 | USART_Transmit(data = USART_Receive()); // receive on byte, send it |
49 | PORTB = data; // and write to Port B |
50 | }
|
51 | }
|