Standard libraries unknown in IDE V1.5.1r2

Hello all,

I'am new to this forum and thats my first Post :slight_smile:

Yes, I' am aware of this tread: http://arduino.cc/forum/index.php/topic,138226.0.html

I experienced the following issue:
I started the development with my brand new Arduino Due board.
My Programm is very large and it have to move it from the Mega 2560.

But all my self created classes won't work anymore.
It seems that the IDE is not including the files properly.

For example:

  • Class files: Time.h / Time.cpp
  • Class needs files: Ethernet.h / EthernetUdp.h / Arduino.h / Wire.h / SPI.h
  • Class location: /libraries/Time/..

Is this a known issue in the 1.5.1r2 or have you changed the way of including libraries?
For example do I need to add an prefix or path?

I also experienced issues with classes from other developers where the object is declared as external. Here it was helpful to build a pointer rather than using external declaration.

I am the originator of the other thread. It is likely that both of our problems have a common cause in the new IDE. The source of the problem is likely known only to the IDE creator. I'm going to watch both threads for clues. Until then, I'll just continue with the Mega.

Hello Arctic_Eddie,

It took me 1/2 pot of coffee but it is now working.
I included ALL headers in the main programm.

My class CTIME.h starts now:
#ifndef TIME_H
#define TIME_H

#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Arduino.h>

My Programm starts now:
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>

void setup() { }

Maybe this is also the solution for your problem..

Just tried it and no go. I just really find it odd that compiling for the Mega works and the Due doesn't, in the same IDE.

It seems you are right.
I'm struggling with some libraries..

I tried to compile the OneWire library and run into an very excellent handled error:

// Platform specific I/O definitions

#if defined(__AVR__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint8_t
#define IO_REG_ASM asm("r30")
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))

#elif defined(__PIC32MX__)
#include <plib.h>  // is this necessary?
#define PIN_TO_BASEREG(pin)             (portModeRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+4)) & (mask)) ? 1 : 0)  //PORTX + 0x10
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+2)) = (mask))            //TRISXSET + 0x08
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) = (mask))            //TRISXCLR + 0x04
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+8+1)) = (mask))          //LATXCLR  + 0x24
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+8+2)) = (mask))          //LATXSET + 0x28

#else
#error "Please define I/O register types here"
#endif

But never the less, i don't have the knowledge at the moment for creating the correct platform specific definitions. My opinion is that this is a good example for an incompatible library (based on platform / CPU change)

Hi.

I'm struggling in the same onewire lib right now.

I've made it to compile, but it doesn't work anyway.

in the defines I've this:

// Platform specific I/O definitions

#if defined(__AVR__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint8_t
#define IO_REG_ASM asm("r30")
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))

#elif defined(__SAM3X8E__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))
#include "pgmspace.h" 

#elif defined(__PIC32MX__)
//- #include <plib.h>  // is this necessary?
#define PIN_TO_BASEREG(pin)             (portModeRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+4)) & (mask)) ? 1 : 0)  //PORTX + 0x10
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+2)) = (mask))            //TRISXSET + 0x08
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) = (mask))            //TRISXCLR + 0x04
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+8+1)) = (mask))          //LATXCLR  + 0x24
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+8+2)) = (mask))          //LATXSET + 0x28

#else
#error "Please define I/O register types here"
#endif

the line #include "pgmspace.h" call the attached file.

The program compiles and works, except that I don't have temperature readings.

I'm looking for understanding of this line:

#define IO_REG_ASM asm("r30")

This line is present for AVR, and since this is called in the communication functions, this might be the problem.

If anyone can explain this line, maybe I can move forward faster.

Help is appreciated, the developers of onewire doesn't seem to care about Due.

Regards,

Joao

pgmspace.h (1.23 KB)

It looks like an assembly language reference to an I/O port register. Whatever it does in AVR is not likely the same in Due.

Picking this function:

uint8_t OneWire::reset(void)
{
	IO_REG_TYPE mask = bitmask;
	volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
	uint8_t r;
	uint8_t retries = 125;

	noInterrupts();
	DIRECT_MODE_INPUT(reg, mask);
	interrupts();
	// wait until the wire is high... just in case
	do {
		if (--retries == 0) return 0;
		delayMicroseconds(2);
	} while ( !DIRECT_READ(reg, mask));

	noInterrupts();
	DIRECT_WRITE_LOW(reg, mask);
	DIRECT_MODE_OUTPUT(reg, mask);	// drive output low
	interrupts();
	delayMicroseconds(500);
	noInterrupts();
	DIRECT_MODE_INPUT(reg, mask);	// allow it to float
	delayMicroseconds(80);
	r = !DIRECT_READ(reg, mask);
	interrupts();
	delayMicroseconds(420);
	return r;
}

this line

volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;

Seems to be declaring 2 vars of IO_REG_TYPE (beeing uint32_t by macro defenition previously)

*reg
IO_REG_ASM

But I don't understand why the IO_REG_ASM.

Shouldn't this line be just:

volatile IO_REG_TYPE *reg = baseReg;

?

Not able to help you much here. I did find this on Google. There are some hits using just the IO_REG_ASM search term. Keep in mind that the libraries are dealing with 8 bit AVR processors and we're trying to make them run with a Due.

I also found this item using the search term asm("r31"). It's a register number which has special pointer capabilities when used in pairs. This is AVR hardware specific so the Due is likely much different.

http://www.avr-asm-tutorial.net/avr_en/beginner/REGISTER.html

The register structure is entirely different. I'm putting mine on the shelf until this is all sorted out.

Humm, this might have something to do with interrupts usage...

I'll try to dig on that, thank you for the links.

Hi again.

I've changed the defines to the code bellow:

#elif defined(__SAM3X8E__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         ((*(base)) & (mask))
#define DIRECT_MODE_INPUT(base, mask)   (base->PIO_OER &= ~mask)
#define DIRECT_MODE_OUTPUT(base, mask)  (base->PIO_OER |= mask)
#define DIRECT_WRITE_LOW(base, mask)    ((*(base)) &= ~mask)
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base)) |= mask)
#include "pgmspace.h"

Right now I'm stuck with:

#define DIRECT_MODE_INPUT(base, mask)   (base->PIO_OER &= ~mask)
#define DIRECT_MODE_OUTPUT(base, mask)  (base->PIO_OER |= mask)

The compiler complains that he doens't know member PIO_OER.

I'm looking in the files for this structures but I'm not finding them.

Anyone knows were these structures are?

The idea here, is to make the pin output, or input. If I recall right, this is done with OER.

I've previously used this registers in UTFT lib but in this format:

		REG_PIOX_OER=0xXXXXX

The errors I'm getting from compiler:

"
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp: In member function 'uint8_t OneWire::reset()':
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp:128: error: request for member 'PIO_OER' in '* reg', which is of non-class type 'volatile long unsigned int'
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp:138: error: request for member 'PIO_OER' in '* reg', which is of non-class type 'volatile long unsigned int'
D:\Docs\Arduino\arduino-1.5.1r2_teste\libraries\OneWire\OneWire.cpp:142: error: request for member 'PIO_OER' in '* reg', which is of non-class type 'volatile long unsigned int'
"

Help appreciated. :wink:

PIO_OER ("Output Enable Register") is used in several versions of file component_pio.h. Look in the folders below:

... arduino-1.5.1r2\hardware\arduino\sam\system\CMSIS\Device\ATMEL

HTH,
Jim

Well, still no luck..

I've set all the registers in place same way has the other defines, but no go.

#elif defined(__SAM3X8E__)
#define PIN_TO_BASEREG(pin)             (&(digitalPinToPort(pin)->PIO_PER)) //to get Base PORT address
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+0x3c)) & mask) ? 1 : 0)	/*(Pio Offset: 0x003C) Pin Data Status Register */
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+0x14)) & mask) 	/*(Pio Offset: 0x0014) Output Disable Register */
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+0x10)) & mask)		/*(Pio Offset: 0x0010) Output Enable Register */
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+0x34)) & mask)		/*(Pio Offset: 0x0034) Clear Output Data Register */
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+0x30)) & mask)		/*(Pio Offset: 0x0030) Set Output Data Register */
#include "pgmspace.h"

By the way, in the line

#define DIRECT_READ(base, mask) ((((base+0x3c)) & mask) ? 1 : 0) /(Pio Offset: 0x003C) Pin Data Status Register */

what is the meaning of

 ? 1 : 0

?

That's a conditional assignment statement. My link to Wikipedia won't print correctly. Do a search for "C++ ?:"

This link will work.

Let's look at the line.

#define DIRECT_READ(base, mask) ((((base+0x3c)) & mask) ? 1 : 0) /(Pio Offset: 0x003C) Pin Data Status Register */

The line has four parts.

Part 1 is #define DIRECT_READ(base, mask) // The part receiving a value

Part 2 is (((*(base+0x3c)) & mask) ? // A conditional test, true or false

Part 3 is 1: // Value assigned if test is true

Part 4 is 0 // Value assigned if test is false

This is what happens. If part 2 is true then part 1 receives part 3(1). If part 2 is false then part 1 receives part 4(0).

It's the same as:

if( part2 == true )
Part 1 has a 1 appended to the end
else
Part 1 has a 0 appended to the end

Ok, thank you for the explanation.

Well, this should work, I'm clueless...

I'll move for a simple test program with onewire and see what happen. Just in the event that the problem is my program and not the lib...

interrupts()
and
nointerrupts()

Are system functions to enable and disable interrupts at a given time, right?

Right, but the spelling of the second one is noInterrupts();

http://arduino.cc/en/Reference/NoInterrupts