I’m using a library to read/write to FRAM non volatile. The library works but I don’t understand how a #define is not doing what I thought.
The library driver defaults to serial outputting Device info via the serial port. What I don’t understand is why I cannot disable this output with a “#define SERIAL_DEBUG = 0” in my program.
The library .h file has (see below for more of the .h file code.
// Enabling debug I2C - comment to disable / normal operations
#ifndef SERIAL_DEBUG
#define SERIAL_DEBUG 1
#endif
I think this says: if “SERIAL_DEBUG” has not been defined then make it =1 . However my program does define “SERIAL_DEBUG” as 0 show this define should not be processed.
Is this an IDE bug I read from a 2011 post? Or am I missing something?
Then in the library .cpp file is the code:
#if defined(SERIAL_DEBUG) && (SERIAL_DEBUG == 1)
which I just don’t understand why this construction? It seems to work but it seems redundant.
Thanks John.
The below code are just larger excepts of the above, if it helps understand my questionably constructed questions.
the driver can be found here: GitHub - sosandroid/FRAM_MB85RC_I2C: Arduino library for I2C FRAM - Fujitsu MB85RC & Cypress FM24, CY15B · GitHub
/**** first lines of my program ********************************/
#define SERIAL_DEBUG = 0
#include <Wire.h>
#include <math.h>
#include <FRAM_MB85RC_I2C.h>
//define a struct of various data types
struct sensorMaxAlltimeure {
uint16_t CO2;
uint16_t VOC;
uint16_t NOx;
uint16_t PM1;
uint16_t PM25;
uint16_t PM10;
};
/**** FRAM_MB85RC_I2C.h ***********************************************/
#ifndef _FRAM_MB85RC_I2C_H_
#define _FRAM_MB85RC_I2C_H_
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <Wire.h>
// Enabling debug I2C - comment to disable / normal operations
#ifndef SERIAL_DEBUG
#define SERIAL_DEBUG 1
#endif
// IDs
//Manufacturers codes
#define FUJITSU_MANUFACT_ID 0x00A
#define CYPRESS_MANUFACT_ID 0x004
#define MANUALMODE_MANUFACT_ID 0xF00
#define MANUALMODE_PRODUCT_ID 0xF00
#define MANUALMODE_DENSITY_ID 0xF00
/**************************************************************************/
#include <stdlib.h>
#include <Wire.h>
#include "FRAM_MB85RC_I2C.h"
first lines of the library source program: FRAM_MB85RC_I2C.cpp
/*========================================================================*/
/* PUBLIC FUNCTIONS */
/*========================================================================*/
void FRAM_MB85RC_I2C::begin(void) {
byte deviceFound = FRAM_MB85RC_I2C::checkDevice();
#if defined(SERIAL_DEBUG) && (SERIAL_DEBUG == 1)
Serial.println(SERIAL_DEBUG);
if (!Serial) Serial.begin(9600);
if (Serial){
Serial.println("FRAM_MB85RC_I2C object created");
Serial.print("I2C device address 0x");
Serial.println(i2c_addr, HEX);
Serial.print("WP pin number ");
Serial.println(wpPin, DEC);
Serial.print("Write protect management: ");
if(MANAGE_WP) {
Serial.println("true");
}
else {
Serial.println("false");
}
if(deviceFound == ERROR_0) {
Serial.println("Memory Chip initialized");
FRAM_MB85RC_I2C::deviceIDs2Serial();
}
else {
Serial.println("Memory Chip NOT FOUND");
}
Serial.println("...... ...... ......");
}
#endif
return;