Hallo Leute, so jetzt bin ichs nochmal. Ich bin heut schon fast am verzweifeln, weil ich versuche eine Verbindung zwischen meinem Arduino Mega2560 Board und dem PC aufzubauen. Das ganze soll ohne die Arduino IDE durchgeführt werden. -> C-Program über Atmel Studio 7 Das Ziel ist eigentlich die Bibliothek von Peter Fleury zu verwenden. (ebenfalls probiert und das Programm läuft auch nicht) Da das aber jetzt nicht geklappt hat wollte ich es vorerst mal ohne die Bibliothek probieren - leider funktionierts wieder nicht. Eig. sollte das Board z.B. test empfangen und wieder an den PC zurückschicken. Als Terminalprogramm verwende ich das von Atmel Studio bereitgestellte.
1 | #define FOSC 16000000 // Clock Speed
|
2 | #define BAUD 9600
|
3 | #define MYUBRR FOSC/16/BAUD-1
|
4 | #include <avr/io.h> |
5 | unsigned char USART_Receive( void ) |
6 | {
|
7 | /* Wait for data to be received */
|
8 | while ( !(UCSR0A & (1<<RXC0)) ) |
9 | ;
|
10 | /* Get and return received data from buffer */
|
11 | return UDR0; |
12 | }
|
13 | void USART_Transmit( unsigned char data ) |
14 | {
|
15 | /* Wait for empty transmit buffer */
|
16 | while ( !( UCSR0A & (1<<UDRE0)) ) |
17 | ;
|
18 | /* Put data into buffer, sends the data */
|
19 | UDR0 = data; |
20 | }
|
21 | void USART_Init( unsigned int ubrr) |
22 | {
|
23 | /* Set baud rate */
|
24 | UBRR0H = (unsigned char)(ubrr>>8); |
25 | UBRR0L = (unsigned char)ubrr; |
26 | /* Enable receiver and transmitter */
|
27 | UCSR0B = (1<<RXEN0)|(1<<TXEN0); |
28 | /* Set frame format: 8data, 1stop bit */
|
29 | UCSR0C = (3<<UCSZ00); |
30 | //UCSR0C |= ((1<<UCSZ01) | (1<<UCSZ00));
|
31 | }
|
32 | int main(void) |
33 | {
|
34 | USART_Init ( MYUBRR ); |
35 | |
36 | /* Replace with your application code */
|
37 | while (1) |
38 | {
|
39 | USART_Transmit(USART_Receive()); |
40 | }
|
41 | }
|
Über jegliche Hilfe wäre ich dankbar.