Arduino SetBit error in Arduino compie for ESP32 Dev Rev C board.

ahurley
Posts: 1
Joined: Mon Jan 21, 2019 8:11 pm

Arduino SetBit error in Arduino compie for ESP32 Dev Rev C board.

Postby ahurley » Mon Jan 21, 2019 8:37 pm

Hello,

Here is some code setting up SDA and SCL in some Arduino code I am trying to compile.
  1.  
  2. void I2C_Setup(void)
  3. {
  4.     // Set SDA and SCL to inputs
  5.     //
  6.     #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__)
  7.         SetBit(PORTC, 4);
  8.         SetBit(PORTC, 5);
  9.     #else
  10.         SetBit(PORTD, 0);
  11.         SetBit(PORTD, 1);
  12.     #endif
  13.     //
  14.     // Set prescaler and clock frequency
  15.     //
  16.     ClearBit(TWSR, TWPS0);
  17.     ClearBit(TWSR, TWPS1);
  18.     TWBR = ((F_CPU / 100000) - 16) / 2;
  19.     //
  20.     // Enable module, and set to ACK
  21.     //
  22.     SetBit(TWCR, TWEA);
  23.     SetBit(TWCR, TWEN);
  24. }



Has anyone seen this error compiling in Arduino Enviroment 1.8.6?




Arduino: 1.8.6 (Windows 7), Board: "ESP32 Dev Module, Disabled, Default, 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'void I2C_Setup()':

I2C.cpp:48:10: error: 'PORTD' was not declared in this scope

SetBit(PORTD, 0);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:11:28: note: in definition of macro 'SetBit'

#define SetBit(VAR,Index) VAR |= (1<<Index)

^

I2C.cpp:54:11: error: 'TWSR' was not declared in this scope

ClearBit(TWSR, TWPS0);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:12:30: note: in definition of macro 'ClearBit'

#define ClearBit(VAR,Index) VAR &= (uint8_t)(~(1<<Index))

^

I2C.cpp:54:17: error: 'TWPS0' was not declared in this scope

ClearBit(TWSR, TWPS0);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:12:52: note: in definition of macro 'ClearBit'

#define ClearBit(VAR,Index) VAR &= (uint8_t)(~(1<<Index))

^

I2C.cpp:55:17: error: 'TWPS1' was not declared in this scope

ClearBit(TWSR, TWPS1);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:12:52: note: in definition of macro 'ClearBit'

#define ClearBit(VAR,Index) VAR &= (uint8_t)(~(1<<Index))

^

I2C.cpp:56:2: error: 'TWBR' was not declared in this scope

TWBR = ((F_CPU / 100000) - 16) / 2;

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:12:0:

I2C.cpp:60:9: error: 'TWCR' was not declared in this scope

SetBit(TWCR, TWEA);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:11:28: note: in definition of macro 'SetBit'

#define SetBit(VAR,Index) VAR |= (1<<Index)

^

I2C.cpp:60:15: error: 'TWEA' was not declared in this scope

SetBit(TWCR, TWEA);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:11:39: note: in definition of macro 'SetBit'

#define SetBit(VAR,Index) VAR |= (1<<Index)

^

I2C.cpp:61:15: error: 'TWEN' was not declared in this scope

SetBit(TWCR, TWEN);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:11:39: note: in definition of macro 'SetBit'

#define SetBit(VAR,Index) VAR |= (1<<Index)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'void I2C_Reset()':

I2C.cpp:199:2: error: 'TWCR' was not declared in this scope

TWCR = 0;

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:12:0:

I2C.cpp:200:15: error: 'TWEA' was not declared in this scope

SetBit(TWCR, TWEA);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:11:39: note: in definition of macro 'SetBit'

#define SetBit(VAR,Index) VAR |= (1<<Index)

^

I2C.cpp:201:15: error: 'TWEN' was not declared in this scope

SetBit(TWCR, TWEN);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\defs.h:11:39: note: in definition of macro 'SetBit'

#define SetBit(VAR,Index) VAR |= (1<<Index)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'uint8_t I2C_start()':

I2C.cpp:220:2: error: 'TWCR' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);

^

I2C.cpp:220:13: error: 'TWINT' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);

^

I2C.cpp:220:24: error: 'TWSTA' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);

^

I2C.cpp:220:35: error: 'TWEN' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:10:0:

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:229:6: note: in expansion of macro 'TWI_STATUS'

if((TWI_STATUS == START) || (TWI_STATUS == REPEATED_START))

^

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:233:5: note: in expansion of macro 'TWI_STATUS'

if(TWI_STATUS == LOST_ARBTRTN)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'uint8_t I2C_stop()':

I2C.cpp:244:2: error: 'TWCR' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWEN)| (1<<TWSTO);

^

I2C.cpp:244:13: error: 'TWINT' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWEN)| (1<<TWSTO);

^

I2C.cpp:244:24: error: 'TWEN' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWEN)| (1<<TWSTO);

^

I2C.cpp:244:35: error: 'TWSTO' was not declared in this scope

TWCR = (1<<TWINT)|(1<<TWEN)| (1<<TWSTO);

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'uint8_t I2C_sendAddress(uint8_t)':

I2C.cpp:258:2: error: 'TWDR' was not declared in this scope

TWDR = ui8Address;

^

I2C.cpp:260:2: error: 'TWCR' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

I2C.cpp:260:13: error: 'TWINT' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

I2C.cpp:260:26: error: 'TWEN' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:10:0:

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:269:6: note: in expansion of macro 'TWI_STATUS'

if((TWI_STATUS == MT_SLA_ACK) || (TWI_STATUS == MR_SLA_ACK))

^

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:274:6: note: in expansion of macro 'TWI_STATUS'

if((TWI_STATUS == MT_SLA_NACK) || (TWI_STATUS == MR_SLA_NACK))

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'uint8_t I2C_sendByte(uint8_t)':

I2C.cpp:287:2: error: 'TWDR' was not declared in this scope

TWDR = ui8Data;

^

I2C.cpp:289:2: error: 'TWCR' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

I2C.cpp:289:13: error: 'TWINT' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

I2C.cpp:289:26: error: 'TWEN' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:10:0:

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:298:5: note: in expansion of macro 'TWI_STATUS'

if(TWI_STATUS == MT_DATA_ACK)

^

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:302:5: note: in expansion of macro 'TWI_STATUS'

if(TWI_STATUS == MT_DATA_NACK)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'uint8_t I2C_receiveByte(uint8_t)':

I2C.cpp:319:3: error: 'TWCR' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);

^

I2C.cpp:319:14: error: 'TWINT' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);

^

I2C.cpp:319:27: error: 'TWEN' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);

^

I2C.cpp:319:39: error: 'TWEA' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);

^

I2C.cpp:323:3: error: 'TWCR' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

I2C.cpp:323:14: error: 'TWINT' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

I2C.cpp:323:27: error: 'TWEN' was not declared in this scope

TWCR = (1<<TWINT) | (1<<TWEN);

^

I2C.cpp:325:10: error: 'TWCR' was not declared in this scope

while(!(TWCR & (1<<TWINT)))

^

I2C.cpp:325:21: error: 'TWINT' was not declared in this scope

while(!(TWCR & (1<<TWINT)))

^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:10:0:

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:333:5: note: in expansion of macro 'TWI_STATUS'

if(TWI_STATUS == LOST_ARBTRTN)

^

I2C.h:15:26: error: 'TWSR' was not declared in this scope

#define TWI_STATUS (TWSR & 0xF8)

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp:339:7: note: in expansion of macro 'TWI_STATUS'

if(((TWI_STATUS == MR_DATA_NACK) && (!ack)) ||

^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_428880\sketch\I2C.cpp: In function 'uint8_t I2C_Read2(uint16_t, uint8_t*, uint8_t)':

I2C.cpp:445:12: error: 'TWDR' was not declared in this scope

*pData = TWDR;

^

exit status 1
'PORTD' was not declared in this scope

Thanks in advance,
Andy

Who is online

Users browsing this forum: No registered users and 61 guests