Arduino expected ')' before '*' token - c

I was trying to seperate my old working code in modules but I got always this error.
"nfc_read.h:24: error: expected ')' before '*' token"
this is line 24:
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength);
not sure what is wrong in the code...
In my header nfc_read.h:
#ifndef _nfc_read_h_
#define _nfc_read_h_
//Libarys
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
void setup_adafruit(int mode);
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength);//<--here is the error
#endif
Maybe here is the mistake somewhere:
#include "nfc_read.h"
#define IRQ (2) // IRQ = Interrupt request uint8 (input)
#define RESET (3) // Not connected by default on the NFC Shield uint8 (output)
void setup_adafruit(int mode)
{
Adafruit_NFCShield_I2C nfc(IRQ, RESET); //Funktionspointer....Pins konfigurieren IRQ => input ,RESET => output
Serial.println("Welcome this application will read your UID of your ISO14443A-Card"); //Willkommens Text
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find Arduino board");
while (1); // halt
}
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A card");
}
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength)
{
*success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
}

Perhaps this will help?
#ifndef _nfc_read_h_
#define _nfc_read_h_
//Libarys
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
Add the following lines:
#include <stdint.h>
#ifndef boolean
#define boolean int
#endif
The above lines will ensure that the proper types are defined.
void setup_adafruit(int mode);
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength);//<--here is the error
#endif

Related

main.c isn't recognising variables from keypad.c [duplicate]

This question already has answers here:
How do I use extern to share variables between source files?
(19 answers)
Closed 2 years ago.
I've been trying to program an atmega328p in Atmel Studio (it's fun), but when I tried to separate my keypad code into it's own c file, I got an error.
Error 'keypad' undeclared (first use in this function) invisible_alarm C:\Users\kenkr\Documents\Atmel Studio\7.0\invisible_alarm\invisible_alarm\main.c 39
keypad is defined in a separate file, and I've ruled a few things out:
I didn't forget the h file (Using a symbol defined in keypad.h works)
The compiler isn't ignoring keypad.c (Errors in keypad.c appear in the compile output)
I didn't forget to add the .c/.h file to the project (They appear in the solution explorer)
I suspect the build order is messed up, but I'm not sure where build order is set in Atmel Studio, but that's just a guess. I put a sample of my files below. The only errors are from main.c referencing keypad.c.
// main.c
#define F_CPU 16000000
#define NULL 0
#include <util/delay.h>
#include <avr/io.h>
#include "lcd.h"
#include "keypad.h"
void example() {
int header_example = KEY_1; // From keypad.h, no error
uint16_t c_example = keypad; // from keypad.c, error
}
// ...
// keypad.h
#ifndef _KEYPAD_H_
#define _KEYPAD_H_
#define KEY_1 0
#define KEY_4 1
// ...
#endif
// keypad.c
#include <avr/io.h>
#include <util/delay.h>
#include "keypad.h"
#define NULL 0
uint16_t keypad = 0x0000;
// ...
You need to declare the variable in the header file:
// keypad.h
#ifndef _KEYPAD_H_
#define _KEYPAD_H_
#include <stdint.h> // commonly needed for uint16_t
#define KEY_1 0
#define KEY_4 1
// ...
extern uint16_t keypad;
#endif

error in struct decleration in header files

port_pin.h
#ifndef __PORT_PIN_H__
#define __PORT_PIN_H__
typedef enum
{
IO_PORT_A = ((uint16_t)0), /* IO Port A Selected */
IO_PORT_B = ((uint16_t)1), /* IO Port B Selected */
IO_PORT_NONE = ((uint16_t)0xFF) /* No IO Port Selected */
}PortName_t;
/* IO Driver GPIO Pin Numbers */
typedef enum
{
IO_PIN_0 = ((uint16_t)0), /* Pin 0 selected */
IO_PIN_1 = ((uint16_t)1), /* Pin 1 selected */
IO_PIN_2 = ((uint16_t)2), /* Pin 2 selected */
IO_PIN_3 = ((uint16_t)3), /* Pin 3 selected */
}PinNumber_t;
hal_io.h
#ifndef __HAL_IO_H__
#define __HAL_IO_H__
#ifdef DEF_HAL_IO
#define EXTERN_HAL_IO
#else
#define EXTERN_HAL_IO extern
#endif
EXTERN_HAL_IO void HalIo_fct(PortName_t, PinNumber_t);
#endif
drv_io.h
#ifndef __DRV_IO_H__
#define __DRV_IO_H__
#ifdef DEF_DRV_IO
#define EXTERN_DRV_IO
#else
#define EXTERN_DRV_IO extern
#endif
EXTERN_DRV_IO Status_t DDrvIOPinSet_fct(const BoardCfgPortPin_t *pointer);
#endif
board_cfg.h
#ifndef __BOARD_CFG_H__
#define __BOARD_CFG_H__
#ifdef DEF_BOARD_CFG
#define EXTERN_BOARD_CFG
#else
#define EXTERN_BOARD_CFG extern
#endif
/* IO driver Gpio Port and Pin Configuration */
typedef struct
{
PortName_t Name_en; /* Specifies the IO Port module */
/* This parameter can be a value of #ref */
/* GpioPort_t */
PinNumber_t PinNo_en; /* Specifies the IO Pin number */
/* This parameter can be a value of #ref */
/* PinNumber_t */
}BoardCfgPortPin_t;
EXTERN_BOARD_CFG const BoardCfgPortPin_t BoardCfgPortPin_sta[4];
EXTERN_BOARD_CFG void BoardCfg_fct();
#endif
main.c
#include <stdio.h>
#include "common.h"
#include "port_pin.h"
#include "board_cfg.h"
#include "drv_io.h"
int main()
{
BoardCfg_fct();
printf("\n\n");
return 0;
}
hal_io.c
#define DEF_HAL_IO
#include <stdio.h>
#include "common.h"
#include "port_pin.h"
#include "hal_io.h"
void HalIo_fct(PortName_t PortName_en, PinNumber_t PinNo_en)
{
printf("\nIN HAL\n");
printf("PORTNAME : %d, PIN NUMBER : %d", PortName_en, PinNo_en);
}
drv_io.c
#define DEF_DRV_IO
#include <stdio.h>
#include "common.h"
#include "port_pin.h"
#include "hal_io.h"
#include "board_cfg.h"
#include "drv_io.h"
Status_t DDrvIOPinSet_fct(const BoardCfgPortPin_t *pointer)
{
printf("\nin DRV IO \n");
HalIo_fct(pointer->Name_en, pointer->PinNo_en);
return (PASS);
}
board_cfg.c
#define DEF_BOARD_CFG
#include <stdio.h>
#include "common.h"
#include "port_pin.h"
#include "drv_io.h"
#include "board_cfg.h"
const BoardCfgPortPin_t BoardCfgPortPin_sta[4] =
{
{ IO_PORT_B, IO_PIN_0 }, /* SENSE_INV_TEMP */
{ IO_PORT_B, IO_PIN_1 }, /* SENSE_INV_AC */
{ IO_PORT_B, IO_PIN_2 }, /* BUZZER */
{ IO_PORT_B, IO_PIN_3 }, /* STAUS_230V_AC */
};
void BoardCfg_fct()
{
DDrvIOPinSet_fct(&BoardCfgPortPin_sta[0]);
DDrvIOPinSet_fct(&BoardCfgPortPin_sta[1]);
DDrvIOPinSet_fct(&BoardCfgPortPin_sta[2]);
DDrvIOPinSet_fct(&BoardCfgPortPin_sta[3]);
}
Regarding the above files, when I try to compile the code I am getting the following errors:
drv_io.h(10): error C2143: syntax error : missing ')' before '*'
drv_io.h(10): error C2143: syntax error : missing '{' before '*'
drv_io.h(10): error C2059: syntax error : ')'
If I comment the code in board_cfg.h
/* IO driver Gpio Port and Pin Configuration */
typedef struct
{
PortName_t Name_en; /* Specifies the IO Port module */
/* This parameter can be a value of #ref */
/* GpioPort_t */
PinNumber_t PinNo_en; /* Specifies the IO Pin number */
/* This parameter can be a value of #ref */
/* PinNumber_t */
}BoardCfgPortPin_t;
and add it to port_pin.h, I could compile the code successfully.
But I need to have the struct in board_cfg.h only
Why am I getting this error?
In the file board_cfg.c, it has drv_io.h first followed by board_cfg.h. However, the delaration of DDrvIOPinSet_fct has an argument of type BoardCfgPortPin_t which is defined in board_cfg.h. Since drv_io.h is listed first, BoardCfgPortPin_t hasn't been declared yet. This is what is causing the error.
Your header files are dependent on each other. Rather than depending on the files that include them to put things in the right order, each header file needs to include the other headers they depend on.
In port_pin.h, add #include <stdint.h>
In hal_io.h, add #include "port_pin.h"
In drv_io.h, add #include "board_cfg.h" and #include "common.h"
In board_cfg.h add #include "port_pin.h"
By doing this, each header has everything it needs. Then it doesn't matter in which order they are included by source files.
Also, you don't need any of the defines related to extern. Function declarations are extern by default.
In line 10 of drv_io.h you have
EXTERN_DRV_IO Status_t DDrvIOPinSet_fct(const BoardCfgPortPin_t *pointer);
So you are using BoardCfgPortPin_t which means that the compiler has to know at this point what BoardCfgPortPin_t is. There are several ways to achieve this:
#include board_cfg.h in drv_io.h before line 10
use a forward declaration: put typedef struct BoardCfgPortPin_t; before line 10
make sure all .c files include board_cfg.h before drv_io.h; this is already the case for all but board_cfg.c

header file include another header file generate redefinition

Does the header file couldn't include another header file in C?
I download the code from Nuvoton website, for Keil C51 project, use the UART sample code, just add the file "EasyTransfer.h" and include "Typedef.h", the result shows lots of error message below.
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(1): error C231: 'BIT': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(2): error C231: 'UINT8': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(3): error C231: 'UINT16': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(4): error C141: syntax error near 'UINT32'
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(6): error C231: 'uint8_t': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(7): error C231: 'uint16_t': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(8): error C141: syntax error near 'uint32_t'
The "EasyTransfer.h" is simple, just few of lines
#ifndef EasyTransfer_h
#define EasyTransfer_h
#include "Typedef.h"
uint8_t * address; //address of struct
#endif
The following is the main code and source link, I think it could be helpful to understand my question.
#define Uart_Port_Sel 0x00
#include <stdio.h>
#include "N79E85x.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include "Version.h"
#include "EasyTransfer.h"
UINT8 u8Uart_Data;
//-----------------------------------------------------------------------------------------------------------
void main (void)
{
AUXR1 |= Uart_Port_Sel; // Select P10/P11 as UART pin(default)
InitialUART0_Timer1(9600); // 9600 Baud Rate # 11.0592MHz
Show_Version_Number_To_PC();
ES = 1; // Enable serial interrupt
EA = 1; // Enable global interrupt
while(1); // Endless
}
//-----------------------------------------------------------------------------------------------------------
void UART_ISR(void) interrupt 4
{
if (RI == 1)
{ // If reception occur
RI = 1; // Clear reception flag for next reception
u8Uart_Data = SBUF; // Read receive data
SBUF = u8Uart_Data; // Send back same data on UART
}
else TI = 0; // If emission occur
// Clear emission flag for next emission
}
You should not include Typedef.h multiple times since there is no header include guard in Typedef.h.
Your main source includes Typedef.h and EasyTransfer.h at the same time, this causes redefinition errors because EasyTransfer.h includes Typedef.h too. Just like your main source includes Typedef.h twice, and WITHOUT header include guard!
I suggest you just remove the #include "Typedef.h" line from your main source file. Or add header include guard in Typedef.h if you can.

How can I transform a Variable from main.c to another file ( interrupt handler)

I'm working on a new project, I want to write my own protocol. Therefore I have to transform a variable (from main.c) to an interrupt handler file.
this is my IRQHandler.h file:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef stm32f4xx_EXTI0_IRQHAndler_H
#define stm32f4xx_EXTI0_IRQHAndler_H
void EXTI0_IRQHandler(void);
#endif
this is my IRQHandler.C File:
void EXTI0_IRQHandler(void)
{
if(GPIOA->IDR & 0x0001){
USART_SendData(USART1, ConvertedValue);
// GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
EXTI_ClearFlag(EXTI_Line0);
// EXTI_ClearITPendingBit(EXTI_Line0);
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
And the requisite variable is Converted Value, what is in the main file.. and I can't transform... I know it's a reallly easy problem... but I can't solve it now..
Thanks for the help! :)
In IRQHandler.c
#include "IRQHandler.h"
volatile uint8_t ConvertedValue ;
void EXTI0_IRQHandler(void)
{
...
}
Then create IRQHandler.h with:
#if !defined IRQHandler_INCLUDE
#define IRQHandler_INCLUDE
extern volatile uint8_t ConvertedValue ;
#endif
Then in main.c
#include "IRQHandler.h"
int main()
{
ConvertedValue = getValue() ; // or whatever - Converted value is visible/accessible here.
}
Alternatively of course you can define ConveretedValue in main.c and declare it as an external in IRQHandler.c (whether directly or via a header file is your choice - a header file as I have used is preferable as it allows the compiler to perform the type checking.

AVR-GCC - enum error with included header

I am having trouble spotting where I am making a mistake and not sure how to google the solution. I am getting the following error:
In file included from buttons.h:8,
from buttons.c:1:
debug_mode.h:14: error: expected ')' before 'Button'
I have an enum declared in buttons.h
#ifndef BUTTONS_HEADER
#define BUTTONS_HEADER
#include <avr/io.h>
#include <stdbool.h>
#include <util/delay.h>
#include "uart.h"
#include "debug_mode.h"
typedef enum {
NO_BUTTON,
BUTTON1,
BUTTON2,
BUTTON3,
BUTTON4,
BUTTON5,
BUTTON6
}
ButtonFlags;
void CheckButtons();
void SetButtonFlag();
void ProcessButtons();
#endif
I am including it in another header debug_mode.h:
#ifndef DEBUG_MODE_HEADER
#define DEBUG_MODE_HEADER
#include "uart.h"
#include <stdbool.h>
#include <avr/pgmspace.h>
#include "buttons.h"
bool DebugModeEnabled = false;
void SetDebugMode();
void AnnounceDebugMode(bool State);
void DebugAnnounceLEDState();
void DebugAnnounceButtonState(ButtonFlags Button);
#endif
and the debug_mode.c:
#include "debug_mode.h"
void DebugAnnounceButtonState(ButtonFlags Button)
{
SendUARTString_P(DEBUGMODE_BUTTON_PRESSED_MSG);
switch (Button)
{
case 1: SendUARTString_P(DEBUGMODE_BUTTON1_MSG); break;
default: break;
}
}
Any assistance would be appreciated
Your headers buttons.h and debug_mode.h are including each other. You will need to refactor your code in such a way to remove this circular dependency.

Resources