Ich habe im AVR-Studio ein C-Programm geschrieben und möchte nun weitere C-Programmteile einbinden. Das habe ich unter Source-Files <create new sourcefiles> gemacht. Um das zu testen, habe ich im testfile eine Funktion geschrieben, welche ich vom Hauptprogramm aufrufe. Beim Compilieren erhalte ich dann Fehlermeldungen mit ...first use in this function. Muss ich im HP das neue c-File irgendwie bekannt machen?
Heimo G. schrieb: > Ich habe im AVR-Studio ein C-Programm geschrieben und möchte nun weitere > C-Programmteile einbinden. > Das habe ich unter Source-Files <create new sourcefiles> gemacht. > Um das zu testen, habe ich im testfile eine Funktion geschrieben, welche > ich vom Hauptprogramm aufrufe. > > Beim Compilieren erhalte ich dann Fehlermeldungen mit ...first use in > this function. Zeig bitte die ganze Fehlermeldung und deinen Code > Muss ich im HP das neue c-File irgendwie bekannt machen? Nein. Aber wenn du eine Funktion aufrufen willst, brauchst du einen Prototypen, der normalerweise in einem Header File sitzt.
Ich rufe im HP die beiden Funktionen im Testfile: char TX_SPI_Master_Transmit_1 und char TX_Strobe_1 auf. Dieser Code steht im Testfile:
1 | char TX_SPI_Master_Transmit_1(char cCommand, char cData)//, char cStrobe) |
2 | {
|
3 | PORTD &= ~(1<<PD3); // SS = low |
4 | _delay_us(500); // Delaytime before start transmission |
5 | |
6 | SPDR = cCommand; // Start transmission adress to FIFO |
7 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
8 | |
9 | SPDR = cData; // Start transmission data to FIFO |
10 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
11 | |
12 | PORTD |= (1<<PD3); // SS = high |
13 | _delay_us(500); |
14 | |
15 | return SPDR; |
16 | }
|
17 | |
18 | char TX_Strobe_1 (char cCommand) |
19 | {
|
20 | PORTD &= ~(1<<PD3); // SS = low |
21 | _delay_us(50); // Delaytime before init rf-settings |
22 | |
23 | SPDR = cCommand; // STROBE TX |
24 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
25 | |
26 | while (!((PINB) &(1<<PB4))); // Wait for GDO0 to be set -> sync transmitted |
27 | while ((PINB) &(1<<PB4)); // Wait for GDO0 to be cleared -> end of packet |
28 | return SPDR; |
29 | }
|
hier das HP:
1 | #include <avr/io.h> |
2 | #include <util/delay.h> |
3 | #include "SMARTRF_CC2500.h" |
4 | |
5 | void SPI_Master_Init(void) |
6 | {
|
7 | SPCR &= ~(1<<DORD); // Send MSB first |
8 | SPCR |= (1<<MSTR); // Controller = Master |
9 | SPCR &= ~(1<<CPOL); // CLK positiv phase |
10 | SPCR &= ~(1<<CPHA); // Sampling data @ rising edge |
11 | SPCR |= (1<<SPR1); // CLK / 64 = 125kHz |
12 | |
13 | DDRB |= (1<<PB1); // Set MOSI output |
14 | DDRB &= ~(1<<PB0); // Set MISO input |
15 | DDRB |= (1<<PB7); // Set SCK output |
16 | DDRB &= ~(1<<PB4); // Set GDO0 input |
17 | |
18 | DDRD |= (1<<PD3); // Set SS output |
19 | |
20 | SPCR |= (1<<SPE); // SPI enable |
21 | }
|
22 | |
23 | char TX_SPI_Master_Transmit(char cCommand, char cData)//, char cStrobe) |
24 | {
|
25 | PORTD &= ~(1<<PD3); // SS = low |
26 | _delay_us(500); // Delaytime before start transmission |
27 | |
28 | SPDR = cCommand; // Start transmission adress to FIFO |
29 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
30 | |
31 | SPDR = cData; // Start transmission data to FIFO |
32 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
33 | |
34 | PORTD |= (1<<PD3); // SS = high |
35 | _delay_us(500); |
36 | |
37 | return SPDR; |
38 | }
|
39 | |
40 | char TX_Strobe (char cCommand) |
41 | {
|
42 | PORTD &= ~(1<<PD3); // SS = low |
43 | _delay_us(50); // Delaytime before init rf-settings |
44 | |
45 | SPDR = cCommand; // STROBE TX |
46 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
47 | |
48 | while (!((PINB) &(1<<PB4))); // Wait for GDO0 to be set -> sync transmitted |
49 | while ((PINB) &(1<<PB4)); // Wait for GDO0 to be cleared -> end of packet |
50 | return SPDR; |
51 | }
|
52 | |
53 | void main(void) |
54 | {
|
55 | DDRC = 0xFF; |
56 | |
57 | unsigned int i; |
58 | SPI_Master_Init(); // Init SPI |
59 | |
60 | PORTD &= ~(1<<PD3); // SS = low |
61 | _delay_us(500); |
62 | |
63 | SPDR = 0x30; // Reset |
64 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
65 | |
66 | PORTD |= (1<<PD3); // SS = high |
67 | _delay_us(500); |
68 | |
69 | PORTD &= ~(1<<PD3); // SS = low |
70 | _delay_us(500); // Delaytime before init rf-settings |
71 | |
72 | |
73 | |
74 | // ********** Init RF-Settings ***************************************
|
75 | for (i=0; i<=70; i+=2) |
76 | {
|
77 | PORTD &= ~(1<<PD3); // SS = low |
78 | _delay_us(200); // Delaytime before init rf-settings |
79 | SPDR = rf_settings[i]; // Init RF-Settings address |
80 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
81 | |
82 | SPDR = rf_settings[i+1]; // Init RF-Settings data |
83 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete |
84 | |
85 | PORTD |= (1<<PD3); // SS = high |
86 | _delay_us(200); // Delaytime before init rf-settings |
87 | }
|
88 | // *******************************************************************
|
89 | |
90 | PORTD |= (1<<PD3); // SS = high |
91 | _delay_us(500); |
92 | |
93 | PORTD &= ~(1<<PD3); // SS = low |
94 | _delay_us(500); // Delaytime before init rf-settings |
95 | |
96 | /*SPDR = 0x31; // Sync
|
97 | while (!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
98 | PORTD |= (1<<PD3); // SS = high
|
99 | _delay_ms(50);
|
100 | PORTD &= ~(1<<PD3); // SS = low
|
101 | _delay_us(500); // Delaytime before init rf-settings */
|
102 | |
103 | while(1) |
104 | {
|
105 | PORTC = TX_SPI_Master_Transmit(0x3F, 0xAA); //Adresse vom FIFO = 3F |
106 | PORTC = TX_Strobe(0x35); |
107 | _delay_ms(1000); |
108 | PORTC = 0x00; // Clear PORTC |
109 | |
110 | PORTC = TX_SPI_Master_Transmit(0x3F, 0x55); //Adresse vom FIFO = 3F |
111 | PORTC = TX_Strobe(0x35); |
112 | _delay_ms(1000); |
113 | PORTC = 0x00; // Clear PORTC |
114 | _delay_ms(1000); |
115 | |
116 | PORTC = TX_SPI_Master_Transmit_1(0x3F, 0xFF); //Adresse vom FIFO = 3F |
117 | PORTC = TX_Strobe_1(0x35); |
118 | _delay_ms(1000); |
119 | PORTC = 0x00; // Clear PORTC |
120 | _delay_ms(1000); |
121 | }
|
122 | }
|
und hier die Fehlermeldungen: Build started 13.10.2010 at 16:30:01 avr-gcc -mmcu=at90pwm316 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT test.o -MF dep/test.o.d -c ../test.c ../test.c: In function 'TX_SPI_Master_Transmit_1': ../test.c:4: error: 'PORTD' undeclared (first use in this function) ../test.c:4: error: (Each undeclared identifier is reported only once ../test.c:4: error: for each function it appears in.) ../test.c:4: error: 'PD3' undeclared (first use in this function) ../test.c:5: warning: implicit declaration of function '_delay_us' ../test.c:7: error: 'SPDR' undeclared (first use in this function) ../test.c:8: error: 'SPSR' undeclared (first use in this function) ../test.c:8: error: 'SPIF' undeclared (first use in this function) ../test.c: In function 'TX_Strobe_1': ../test.c:21: error: 'PORTD' undeclared (first use in this function) ../test.c:21: error: 'PD3' undeclared (first use in this function) ../test.c:24: error: 'SPDR' undeclared (first use in this function) ../test.c:25: error: 'SPSR' undeclared (first use in this function) ../test.c:25: error: 'SPIF' undeclared (first use in this function) ../test.c:27: error: 'PINB' undeclared (first use in this function) ../test.c:27: error: 'PB4' undeclared (first use in this function) make: *** [test.o] Error 1 Build failed with 14 errors and 1 warnings...
Heimo G. schrieb: > Dieser Code steht im Testfile: > da fehlt #include <avr/io.h> > char TX_SPI_Master_Transmit_1(char cCommand, char cData)//, char > cStrobe) > { > PORTD &= ~(1<<PD3); // SS = low .... Jedes C-File wird unabhängig von allen anderen compiliert. Das heisst aber auch, jedes C-File muss alles includen was es selbst braucht. Dein text.c braucht die Dinge wie Portdefinitionen aus avr/io.h. Also muss es das auch includieren. Und da du auch _delay_us benutzt, musst du auch diesen Header in test.c includen.
Ja, genau das war der Fehler! SUPER es funktioniert. DANKE für die schnelle Hilfe!!!
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.