How to set bits in the PCA9685?

HI
i have a question:
how can i set bits like this?

if(b==0){b=1;
PCA9685_MODE1 |= (1<<SLEEP);
}
else{
PCA9685_MODE1 &= ~(1<<SLEEP);
_delay_ms(1);
PCA9685_MODE1 |= (1<<RESET);
}

it’s not possible to run, because RESET and SLEEP are not decleared, but they are called in the PCA9685 datasheet as that name.

or is there any other way to use the reset mode with an external Interrupt?

thanks in advance

because RESET and SLEEP are not decleared,

So declare them.
What's the problem?
If you have a name clash, call them something like "PCA9685_SLEEP"

(Did you mean "RESTART", and not "RESET"?)

#define SLEEP 0x10
#define RESTART 0x80

when i do this, the errormessages are:

Programm_mit_Timer:92: error: lvalue required as left operand of assignment

PCA9685_MODE1 |= (1<<SLEEP);

^

Programm_mit_Timer:95: error: lvalue required as left operand of assignment

PCA9685_MODE1 &= ~(1<<SLEEP);

^

Programm_mit_Timer:97: error: lvalue required as left operand of assignment

PCA9685_MODE1 |= (1<<RESTART);

^
.
.
.

exit status 1
lvalue required as left operand of assignment

OK, so we've established that PCA9685_MODE1 is not an lvalue.

Because I can't see your code, you're going to have to find out what PCA9685_MODE1 is, and fix it.

Or you could post your code.
Inside code tags.

if it helps^^

Programm mit ISR.txt (16.2 KB)

htler007:
if it helps^^

No, not really, because that doesn't tell me what " PCA9685_MODE1" is (apart from "not an lvalue")

These are the files wich are in the downloaded folder

PCA9685.cpp (2.85 KB)

PCA9685.h (1.81 KB)

PCA9685.cpp (2.85 KB)

PCA9685.h (1.81 KB)

It's an I2C device?

Where are you retrieving the original contents of register PCA9685_MODE1?
(Note: that's the contents of PCA9685_MODE1, not the name of the register itself)

The PCA9685 is a separate chip (connected via I2C), so you can’t just modify its registers by accessing them like local variables in your sketch. You have to use library functions to set them. Looking at the library you quoted, that would be something like:

    writeRegister(PCA9685_MODE1, (byte)0x01);	// reset the device

why is “WIRE” , “_i2caddr” not declared??!!!

and what happens in this two lines?:

WIRE.requestFrom((uint8_t)_i2caddr, (uint8_t)1);
return WIRE.read();

erroe Messages:

Programm_mit_Timer:38: error: ‘WIRE’ was not declared in this scope

WIRE.beginTransmission(0x40);

^

Programm_mit_Timer:42: error: ‘_i2caddr’ was not declared in this scope

WIRE.requestFrom((uint8_t)_i2caddr, (uint8_t)1);

^

C:\Users\Karin & Andreas\Documents\Arduino\Programm_mit_Timer\Programm_mit_Timer.ino: In function ‘void write8(uint8_t, uint8_t)’:

Programm_mit_Timer:47: error: ‘WIRE’ was not declared in this scope

WIRE.beginTransmission(0x40);

^

Programm mit ISR.txt (17 KB)

i looked into "Wire.h", cause "Adafruit_PWMServoDriver.cpp" use this

Wire.h (2.62 KB)

You probably need "#include "wire.h" at the top of your sketch.

Use Wire.h.

It’s spelled Wire. Not WIRE. C is case sensitive.

What is the i2cmaster library you’re using, and why are you using it???

Doesn’t the PCA9685 library supply functions so that you don’t need to directly write registers?

ok, thx ^^, stupid mistake XD
but 1 error is still there...

is still here:

Programm_mit_Timer:38: error: ‘_i2caddr’ was not declared in this scope

Wire.requestFrom((uint8_t)_i2caddr, (uint8_t)1);

^

but why only Wire and not WIRE?
Wire is “orange”, so it’s right, but why uses the cpp. “WIRE” ?

Programm mit ISR.txt (16.9 KB)

You have not defined _i2caddr - not in that scope, and not anywhere else.

That needs to be 0x40 - it's the same address you do in begin transmission().

Wire.requestFrom(0x40,1); should do what you want it to I think?

I'm not sure where you're getting the idea to use WIRE instead of Wire. Everything in C is case sensitive - Wire is different from WIRE. Where did you see "WIRE" used?

ok, got it^^

but why won't the the shiel restart? it only goes to sleep.....

i saw this in the cpp, and i copied this part…:smiley:

Programm mit ISR.txt (16.9 KB)

This is the way how to restart

do u think i make something wrong in my sketch??

from PCA9685.pdf :

Restart mode
If the PCA9685 is operating and the user decides to put the chip to sleep (setting MODE1
bit 4) without stopping any of the PWM channels, the RESTART bit (MODE1 bit 7) will be
set to logic 1 at the end of the PWM refresh cycle. The contents of each PWM register are
held valid when the clock is off.
To restart all of the previously active PWM channels with a few I2C-bus cycles do the
following steps:

  1. Read MODE1 register.
  2. Check that bit 7 (RESTART) is a logic 1. If it is, clear bit 4 (SLEEP). Allow time for
    oscillator to stabilize (500 s).
  3. Write logic 1 to bit 7 of MODE1 register. All PWM channels will restart and the
    RESTART bit will clear.
    Remark: The SLEEP bit must be logic 0 for at least 500 s, before a logic 1 is written into
    the RESTART bit.

so, nobody has an answer xD