Hi,
I know that the octopus is coming with its own firmware and its own
software libraries to control it from the PC.
Nevertheless my goal is to first gather some experience with the
ATmega128 that it contains. Therefore I loaded my own AVR program
instead of the firmware.
Actually the program does not behave as I am expecting: My program is
just be able to send characters and to receive some. To see the result I
write the bits "PORTC = 0xEF;" which drives the LEDs.
My Code was successfully charged on the Octopus Board.
For the application I have a Hterm on PC instaliert.
The Octopus Device ist recognized on my Pc. Because on System>System
Control>Hardware-Manager I can see "LibUSB-Win32Devices" --> "OtopusUSB
Interface Converter and I/O Extension".
although that, when I write the name of the port "LibUSB-Win32Devices"
or "OtopusUSB Interface Converter and I/O Extension" on my Hterm, he
doesn't recognize it. I don't know witch Port the Octopus have. Or I
must proceed in another art.
Please help me I am a beginner and want to work mit Octopus.
thanks for reading.
1 | #ifndef F_CPU
|
2 | #warning "F_CPU was not defined yet, now make up with 4000000"
|
3 | #define F_CPU 4000000L // Systemtakt in Hz - define as long>> Without errors in the computation
|
4 | #endif
|
5 |
|
6 |
|
7 | #define BAUD 9600L
|
8 | #define UBRR_VAL ((F_CPU+BAUD * 8)/(BAUD*16)-1) //clever round
|
9 | #define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) //real baud rate
|
10 | #define BAUD_ERROR ((BAUD_REAL*1000)/BAUD-1000) //Error per thousand
|
11 |
|
12 |
|
13 | #if ((BAUD_ERROR>10)||(BAUD_ERROR<-10))
|
14 | #error Systematic error in the baud rate more than 1% and thus too high!
|
15 | #endif
|
16 |
|
17 |
|
18 | #include <avr/io.h>
|
19 | #include <stdlib.h>
|
20 | #include <inttypes.h>
|
21 | #include <util/delay.h>
|
22 |
|
23 |
|
24 | //for USART0
|
25 | void USART_Init(void)
|
26 | {
|
27 |
|
28 | UBRR0H = (unsigned char)(UBRR_VAL>>8); // Set baud rate
|
29 | UBRR0L = (unsigned char)UBRR_VAL;
|
30 |
|
31 | UCSR0B |= (1<<RXEN)|(1<<TXEN); // Enable receiver and transmitter
|
32 |
|
33 | UCSR0C = (1<<UCSZ00)|(1<<UCSZ01); // Set frame format: 8data, 1stop bit
|
34 |
|
35 | }//end USART_Init()
|
36 |
|
37 | void USART_Putc(unsigned char c)
|
38 | {
|
39 | while (!(UCSR0A & (1<<UDRE0))); // Do nothing until data have been transmited
|
40 |
|
41 | UDR0 = c; // Put data into Buffer, sends the data
|
42 | _delay_ms(10);
|
43 | }//end USART_Putc()
|
44 |
|
45 | //function which send a String Through uart
|
46 | void USART_Puts (char *string)
|
47 | {
|
48 | while( *string != '\0' ) //as long as *string != '\0' so unlike the "stringer end-character"
|
49 | {
|
50 | USART_Putc(*string);
|
51 | string++;
|
52 | }
|
53 | }//end USART_Puts()
|
54 |
|
55 |
|
56 | unsigned char UART_Getc()
|
57 | {
|
58 | while( !(UCSR0A & (1<<RXC)) ); // Do nothing until data have been recieved and is ready to be read from UDR
|
59 |
|
60 | return UDR0; //Get and receive data from Buffer
|
61 | }//end USART_Receive()
|
62 |
|
63 |
|
64 | int main(void)
|
65 | {
|
66 | DDRC = 0xFF; // define as output
|
67 | USART_Init();
|
68 | USART_Puts("\r\n");
|
69 | USART_Puts("Messung gestartet:"); // receives data
|
70 |
|
71 | unsigned char received;
|
72 |
|
73 | while(1)
|
74 | {
|
75 | received = UART_Getc(); // sends data
|
76 | PORTC = 0xEF
|
77 | if(received == 0x0D) // = ENTER-Taste
|
78 | USART_Puts("\r\n");
|
79 | else
|
80 | {
|
81 | USART_Puts("\r\n");
|
82 | USART_Putc(received );
|
83 | if( (received >= 0x61 && received <= 0x7A) //a bis z
|
84 | || (received >= 0x41 && received <= 0x5A) //A bis Z
|
85 | || (received >= 0x30 && received <= 0x39) //0 bis 9
|
86 | || (received == 0x20) ) //<SPACE>
|
87 |
|
88 | USART_Puts("\r\n");
|
89 | USART_Putc(received);
|
90 | USART_Puts("\r\n");
|
91 | }
|
92 | }
|
93 | return 0;
|
94 | } //end main()
|