Forum: Mikrocontroller und Digitale Elektronik [PIC24] error: syntax error before '.' token


von Andreas G. (beastyk)


Lesenswert?

Moin Leute,

ich hab hier ein Problem und komm einfach nicht weiter, kann sich mal 
jemand die Codeschnipsel ansehen und mir vielleicht sagen was ich da 
falsch gemacht habe?!?

Build Output:
1
mfrc522.c:39: error: syntax error before '.' token
2
mfrc522.c: In function 'MFRC522':
3
mfrc522.c:40: error: number of arguments doesn't match prototype
4
mfrc522.h:266: error: prototype declaration
5
mfrc522.c:50: warning: 'return' with no value, in function returning non-void
6
Halting build on first failure as requested.

mfrc522.c:
1
//include basic header definition
2
#include "p24FJ256GA106.h"
3
#include "GenericTypeDefs.h"
4
#include "stdbool.h"
5
#include <stdint.h>
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include "OnePIC_int.h"
10
#include "OnePIC_lcd.h"
11
#include "OnePIC_switch.h"
12
#include "mfrc522.h"
13
#include "TimeDelay.h"
14
#include <spi.h>
15
16
#define CS_PIN_OUT     TRISBbits.TRISB15
17
#define CS_PIN       LATBbits.LATB15
18
#define RST_PIN_OUT    TRISBbits.TRISB13
19
#define RST_PIN       LATBbits.LATB13 
20
21
 * Prepares the output pins.
22
 */
23
24
//PIC24F SS(out)-> MFRC522's SPI slave select input (RB15/PTP6, NSS, active low)
25
//PIC24F reset(out)-> MFRC522's reset and power down input (RB13/PTP4, NRSTPD, ??active low??)
26
BYTE MFRC522(BYTE CS_PIN, BYTE RST_PIN)    
27
{
28
  // Set the chipSelectPin as digital output, do not select the slave yet
29
  _chipSelectPin = CS_PIN;//set _chipSelectPin to CS_Pin -> LATBbits.LATB15
30
  CS_PIN_OUT = 0;      //Set TRISBbits.TRISB15 to output
31
  _chipSelectPin = 1;    // LATBbits.LATB15=1 
32
  
33
  // Set the resetPowerDownPin as digital output, do not reset or power down.
34
  _resetPowerDownPin = RST_PIN; //Set _resetPowerDownPin to RST_PIN -> LATBbits.LATB13
35
  RST_PIN_OUT = 0;    //Set TRISBbits.TRISB13 to output
36
  _resetPowerDownPin = 0;  // LATBbits.LATB13=0
37
 return;
38
}

mfrc522.h:
1
  BYTE MFRC522(BYTE CS_PIN, BYTE RST_PIN);

Ich hoffe das langt an Code und ihr könnt mir helfen!

best wishes
dat
Beast

von g457 (Gast)


Lesenswert?

>
>  * Prepares the output pins.
>  */
   ^^
HTH

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

1
#define CS_PIN_OUT     TRISBbits.TRISB15
2
#define CS_PIN       LATBbits.LATB15
3
#define RST_PIN_OUT    TRISBbits.TRISB13
4
#define RST_PIN       LATBbits.LATB13 
5
6
...
7
8
BYTE MFRC522(BYTE CS_PIN, BYTE RST_PIN)

Was soll eine Funktion (oder ein Funktionsprototyp) mit konstanten 
Werten anstelle von Variablen als Funktionsargumenten anfangen?

Was Du da machst enstpricht dem hier:
1
#define WERT_A 5
2
#define WERT_B 6
3
4
BYTE Funktion(BYTE WERT_A, BYTE WERT_B) 
5
...

Damit kann Dein Compiler aus guten Gründen nichts anfangen.

von Andreas G. (beastyk)


Lesenswert?

Danke an euch Beiden,

bin gerade am rumgrübeln und lese noch etwas über "extern" und 
"volatile" bei Variablen.
Ich hab also nur dem Lat und Tris einen neuen Namen gegeben und das sagt 
aber nichts darüber aus ob da etwas auf 0 oder 1 gesetzt wurde.
Das mach ich ja anscheinend mit/über _chipSelectPin und 
_resetPowerDownPin.
Also wäre es doch angebrachter das ich diese Werte in der Funktion 
übergebe.

Also wenn ich alles so ändere dann meckert mein Linker mit mir rum, ich 
hätte in der main.c und mfrc522.c Variablen doppelt definiert (multiple 
definition) (hier von _chipSelectPin, _resetPowerDownPin und 
uid)...darum lese ich gerade etwas in der FAQ hier im Forum, auch wenn 
es für AVR ist.

Ist der Weg richtig?

Gruß
das C Tutorial lesende
Beast

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Mit "volatile" und "extern" hat Dein Problem nichts zu tun.

Warum versuchst Du Deiner Funktion überhaupt etwas zu übergeben, wenn Du 
doch gleichzeitig in Deiner Funktion mit Konstanten arbeitest?
1
void MFRC522(void)    
2
{
3
  // Set the chipSelectPin as digital output, do not select the slave yet
4
  _chipSelectPin = CS_PIN;       //set _chipSelectPin to CS_Pin -> LATBbits.LATB15
5
  CS_PIN_OUT = 0;                //Set TRISBbits.TRISB15 to output
6
  _chipSelectPin = 1;            // LATBbits.LATB15=1 
7
  
8
  // Set the resetPowerDownPin as digital output, do not reset or power down.
9
  _resetPowerDownPin = RST_PIN;  //Set _resetPowerDownPin to RST_PIN -> LATBbits.LATB13
10
  RST_PIN_OUT = 0;               //Set TRISBbits.TRISB13 to output
11
  _resetPowerDownPin = 0;        // LATBbits.LATB13=0
12
}

Das erste void rührt daher, daß Deine Funktion gar nichts zurückgibt - 
das leere return am Ende ist daher auch überflüssig.

Der Funktionsprototyp in Deiner Headerdatei sieht dann so aus:
1
void MFRC522(void);

Vermutlich haben Deine Variablen _chipSelectPin und resetPowerDownPin 
auch keinen weiteren Nutzen, so daß sich Deine Funktion reduzieren lässt 
auf das hier:
1
void MFRC522(void)    
2
{
3
  // Set the chipSelectPin as digital output, do not select the slave yet
4
  CS_PIN_OUT = 0;   //Set TRISBbits.TRISB15 to output
5
  CS_PIN = 1;       // LATBbits.LATB15=1 
6
  
7
  // Set the resetPowerDownPin as digital output, do not reset or power down.
8
  RST_PIN_OUT = 0;  //Set TRISBbits.TRISB13 to output
9
  RST_PIN = 0;      // LATBbits.LATB13=0
10
}

von Andreas G. (beastyk)


Lesenswert?

nabend Rufus,

im Grunde benutz ich _chipSelectPin und _resetPowerDownPin später in den 
anderen Funktionen wenn es um die Kommunikation mit dem MFRC522 über SPI 
geht, aber du hast natürlich Recht wenn du darauf hinweist das mfrc522 
als Funktion eigentlich nur die Anfangsbedingungen festlegt.
Die Library war im Grunde für den Arduino geschrieben und im 
Orignialcode stand:
1
MFRC522::MFRC522(  byte chipSelectPin,    ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low)
2
          byte resetPowerDownPin  ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low)
3
        )
Das MFRC522:: hab ich für eine Eigenart des Arduino gehalten, vielleicht 
so etwas wie eine übergeordnete Instanz oder sowas.
Alle anderen Funktionen fingen auch so an, aber ohne das MFRC522:: 
machten die Funktionen halt genausoviel Sinn. Hab aber gesehen das die 
Orignialfunktion kein Return zurückgibt, anscheinend hat Arduino das 
nicht so mit dem void....
Mal abgesehen davon darf man wohl auch 2 mal PCD_WriteRegister und 
PCD_ReadRegister als Funkionennamen verwenden, wobei einmal nur ein Byte 
und das andere Mal mehrer Bytes geschrieben/gelesen werden.

Ich danke dir für die Ruhe die du bewahrst beim erklären ;o)

Gruß
dat
Beast

von Andreas G. (beastyk)


Lesenswert?

Andreas G. schrieb:
> Das MFRC522:: hab ich für eine Eigenart des Arduino gehalten, vielleicht
> so etwas wie eine übergeordnete Instanz oder sowas.

Wie gut das ich mich so garnicht gut auskenne.
C++: class MFRC522 -> MFRC522::MFRC522(...,...) -> 
EineKlasse::eineFunktion

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.