Forum: Compiler & IDEs zeiger an Funktion übergeben


von C. S. (chappi)


Lesenswert?

Ich möchte einen Call- By Reference Funktionsaufruf 
starten....eigentlich kein Thema. Nur wenn ich die Adresse übergeben 
will, meckert er:

passaging argument 1 of 'check_ADC' from incompatible pointer type

meine Programm im groben sieht so aus:
1
#include <avr/io.h>
2
#include <util/delay.h>
3
#include <stdint.h>
4
#include <stdlib.h>
5
#include <inttypes.h>
6
#include <math.h>
7
  
8
//prototypes
9
void check_ADC(double *temp_x,uint8_t port,double left, double right);
10
double ADC_read(uint8_t channel);
11
void ADC_init(void);
12
uint8_t ERR = 0;
13
14
int main(void)
15
{
16
    ADC_init();
17
    double *temp1;
18
    [...]
19
20
    check_ADC (&temp1, 3 ,2.3 ,2.6);
21
22
    [...]
23
24
}
25
26
void check_ADC(double *temp_x,uint8_t port,double left, double right)
27
{
28
    *temp_x=ADC_read(port);
29
    _delay_ms(100);
30
31
    if(*temp_x < left || *temp_x > right)
32
       ERR += 1;
33
}
34
35
// initialize ADC
36
void ADC_init(void)
37
{
38
  uint16_t result;  
39
40
  ADMUX = (1<<REFS0);    // reference voltage = AVCC (5V)
41
  ADCSRA |= (1<<ADEN);    //activate ADC
42
43
//"dummy-readout"
44
  ADCSRA |= (1<<ADSC);        
45
  while(ADCSRA & (1<<ADSC));
46
  result = ADCW;
47
}
48
49
double ADC_read(uint8_t channel)
50
{
51
  // Function gets voltage at given ADC-PORT
52
  // and returns the value in volts.
53
  //
54
  ADMUX = (ADMUX &=~(0x1F)) | (channel & 0x1F);// PORT of multiplexer (choose channel)
55
  ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
56
  ADCSRA |= (1<<ADSC);            // single conversion
57
  while(ADCSRA &(1 << ADSC));         // wait for result
58
  return (ADCW/1023.0)*5.0;          // return result
59
}

Das Problem ist der Funktionsaufruf "check_ADC". Dort kommt diese 
Fehlermeldung, wenn ich temp1 mit der Adresse übergebe (also einem " & " 
davor). Sobald ich das " & " wegnehme ist der Fehler nicht mehr da. Wie 
kommt das?

von Frank M. (ukw) (Moderator) Benutzerseite


Lesenswert?

C. S. schrieb:
> int main(void)
> {
>     ADC_init();
>     double *temp1;
             ^
             Das Sternchen muss da weg.

Gruß,

Frank

von C. S. (chappi)


Lesenswert?

ahhhh natürlich!!!!! omg wie peinlich :D

danke!

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
Noch kein Account? Hier anmelden.