Go Down

Topic: Arduino.h and wiring_digital.c problem. (Read 7 times) previous topic - next topic

Baltasar

Thanks cmaglie, but we (me and alvesjc) allready had that included on the changed pinMode version.

The problem is like I said, using directly like this works:

Code: [Select]

#define sbi(reg, bitmask) portOutputRegister(digitalPinToPort(13)) = 0xffffffff & bitmask

B_LED = digitalPinToBitMask(13);
sbi(P_LED,B_LED);


passing the reg var not !

Here is the not working code code:

Code: [Select]

#define sbi(reg, bitmask) reg = 0xffffffff & bitmask

P_LED = portOutputRegister(digitalPinToPort(13));
B_LED = digitalPinToBitMask(13);
sbi(P_LED,B_LED);


Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

stimmer

Code: [Select]
P_LED = portOutputRegister(digitalPinToPort(13));
This line reads the current value of the port output register and stores it in P_LED. This is almost certainly not what you wanted to do.

Baltasar

stimmer , but using that inside de sbi macro works and the led on pin 13 blinks on/off alternating, only does not work if I pass the P_LED.
Check all my projects based on Atmel/Arduino -> www.aqualed-light.com

cmaglie

What's the intended behaviour of sbi? you defined it as:

Code: [Select]

#define sbi(reg, bitmask) reg = 0xffffffff & bitmask


Actually (0xffffffff & bitmask) equals to "bitmask", i don't see why you do this bitwise-AND.

probably you want to do something like that:

Code: [Select]

#define sbi(reg, mask) (reg |= mask)
#define cbi(reg, mask) (reg &= ~mask)

C.

alvesjc

Hi cmaglie.

Yes, it has been tested that way also, in fact, that is the original code.

Code: [Select]
P_LED = portOutputRegister(digitalPinToPort(13));
This line reads the current value of the port output register and stores it in P_LED. This is almost certainly not what you wanted to do.


Stimmer, I think I understand what you mean.

What we are trying to do is to get the port address.

This code in mega works this way:

Code: [Select]

#define sbi(reg, mask) *reg |= mask
#define cbi(reg, mask) *reg &= ~mask

volatile uint8_t * P_LED;
uint16_t B_LED;

void(loop)
{
P_LED = portOutputRegister(digitalPinToPort(13));
B_LED = digitalPinToBitMask(13);
sbi(P_LED,B_LED);
cbi(P_LED,B_LED);
}


But when we ported this code to Due like this:

Code: [Select]

#define sbi(reg, mask) *reg |= mask
#define cbi(reg, mask) *reg &= ~mask

volatile uint32_t * P_LED;
uint32_t B_LED;

void(loop)
{
P_LED = portOutputRegister(digitalPinToPort(13));
B_LED = digitalPinToBitMask(13);
sbi(P_LED,B_LED);
cbi(P_LED,B_LED);
}


It doens't compile complaining that RwREG is not compatible with volatile uint32_t*.

Can you give us a clue why?

I confess, i'm very bad with pointers...

Go Up