Pages: 1 [2]   Go Down
Author Topic: Standard libraries unknown in IDE V1.5.1r2  (Read 3274 times)
0 Members and 1 Guest are viewing this topic.
St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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



Logged

St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This link will work.


http://en.wikipedia.org/wiki/%3F%3A
Logged

St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The math with pointers is failing. I try to add the offset to the base register and it gets a value that I can't explain.

I'm using pin 7 of due.

For this pin, the port address is 400E1200 and PDSR register is 400E123C. This is taken from datasheet.

I've added Serial.println to the reset function to see the backstage.

Code:
uint8_t OneWire::reset(void)
{
IO_REG_TYPE mask = bitmask;
//volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
volatile IO_REG_TYPE *reg = baseReg;
//volatile IO_REG_TYPE *regout = baseOutReg;
Serial.println((long)(&(digitalPinToPort(7)->PIO_PER)),HEX);
Serial.println((long)(reg),HEX);
Serial.println((long)(bitmask),HEX);
volatile uint32_t *value=reg+1;
Serial.println((uint32_t)value,HEX);
uint8_t r;
uint8_t retries = 125;

noInterrupts();
DIRECT_MODE_INPUT(reg, mask);
Serial.println(((*(reg+0x3c))),HEX);

From this serial.print i get:

for -> Serial.println((long)(&(digitalPinToPort(7)->PIO_PER)),HEX);

I have 400E1200

for -> Serial.println((long)(reg),HEX);

I also have 400E1200

for -> Serial.println((long)(bitmask),HEX);

I have 800000

for - > Serial.println((uint32_t)value,HEX);

I have 400E1204 !!!!!!!!!!!!!!  

Remenber that I've done this one line before:

volatile uint32_t *value=reg+1;

Why I don't have 400E1201 ????? smiley-eek
Logged


0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I'll answer myself... smiley-grin

It's because the var that is pointed is from uint32_t type (4 bytes). So increasing 1, is in fact, increasing 4 positions.

I've fixed this this way:

Code:
#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/4))) & mask) ? 1 : 0) /*(Pio Offset: 0x003C) Pin Data Status Register */
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+(0x14/4))) & mask) /*(Pio Offset: 0x0014) Output Disable Register */
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+(0x10/4))) & mask) /*(Pio Offset: 0x0010) Output Enable Register */
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+(0x34/4))) & mask) /*(Pio Offset: 0x0034) Clear Output Data Register */
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+(0x30/4))) & mask) /*(Pio Offset: 0x0030) Set Output Data Register */
#include "pgmspace.h"

But still no temp readings...
Logged


0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok ok.


WORKINGGGGGGGGGGGGGGGG!!!!!!!!!


Just add this to the onewire.h:

Code:
#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+15)) & (mask)) ? 1 : 0) /*(Pio Offset: 0x003C) Pin Data Status Register */
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+5)) = (mask)) /*(Pio Offset: 0x0014) Output Disable Register */
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+4)) = (mask)) /*(Pio Offset: 0x0010) Output Enable Register */
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+13)) = (mask)) /*(Pio Offset: 0x0034) Clear Output Data Register */
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+12)) = (mask)) /*(Pio Offset: 0x0030) Set Output Data Register */
#include "pgmspace.h"

Final code should look like this:

Code:
#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)             (&(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+15)) & (mask)) ? 1 : 0) /*(Pio Offset: 0x003C) Pin Data Status Register */
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+5)) = (mask)) /*(Pio Offset: 0x0014) Output Disable Register */
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+4)) = (mask)) /*(Pio Offset: 0x0010) Output Enable Register */
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+13)) = (mask)) /*(Pio Offset: 0x0034) Clear Output Data Register */
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+12)) = (mask)) /*(Pio Offset: 0x0030) Set Output Data Register */
#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 difference is the equal sine instead the logical AND.

But, I still don't understand why it works this way...

Remenber, the pgmspace.h is in a few older posts in this thread.
Logged


0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can someone test this also?

It worked for me for a while, but then started to give errors.

After a while, lost communication with prob.

Thanks
Logged


0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again.

The problem is around the timers for read and write timeslots. The datasheet from the probe says that the timeslots should be at least 60us long, and this works for arduino and chipkit. but I'm already near 80us and still get one error sometimes, but very spaced.

I'm tweaking those timers to see if i can get 100% success. I'm also considering that the problem may be because I'm reading the prob in the loop, for every cycle I check the probe. Due is a lot faster then Mega, and because of this, maybe I'm getting stuck in some hardware limit of the probe regarding speed. But chipkit is also fast, almost same clock speed and no errors with it.

I'll continue to increase time slot size to see if it gets 100% success. If no more improvements this way, I'll try to see what happens if I start to check the probe once every second for example.

I'll keep posting.

Regards,

Joao
Logged


Pages: 1 [2]   Go Up
Jump to: