RGB LED Driver demo
Dependents: NJU6063_HelloWorld
Diff: NJU6063.cpp
- Revision:
- 4:7a4b9d444b87
- Parent:
- 3:f83202c2ae59
diff -r f83202c2ae59 -r 7a4b9d444b87 NJU6063.cpp --- a/NJU6063.cpp Mon Jan 18 05:07:27 2016 +0000 +++ b/NJU6063.cpp Mon Jan 25 08:59:03 2016 +0000 @@ -1,5 +1,5 @@ #include "NJU6063.h" -#ifndef TARGET_STM +//#ifndef TARGET_STM NJU6063::NJU6063( PinName sda, PinName scl, PinName rst) : _i2c(sda, scl), _rst(rst) { @@ -23,28 +23,30 @@ ret = n; data[0] = 0x00; // Initial chip addres data[1] = NJU6063_MADRES; // multi device address +#ifdef TARGET_NUCLEO_F042K6 + for (uint8_t i=1; i<=n; i++) { + data[2] = i; + ack= _i2c.write(NJU6063_SLAVE, data, 2); + NJU6063_WAIT; + if (ack) { + ret = i-1; + break; + } + else { + ack= _i2c.write(NJU6063_SLAVE, data, 3); + } + } +#else for (uint8_t i=1; i<=n; i++) { data[2] = i; ack= _i2c.write(NJU6063_SLAVE, data, 3); - //printf("%d %02X\n\r", i, ack); NJU6063_WAIT; if (ack) { - //_myI2c->CR1 = ret = i-1; - //int tmp = _myI2c->DR; - //__I2C1_FORCE_RESET(); - //__I2C1_RELEASE_RESET(); - //__HAL_I2C_CLEAR_FLAG(&_myI2cH, I2C_FLAG_AF); - //__HAL_I2C_CLEAR_FLAG(&_myI2cH, I2C_FLAG_AF); - //printf("%x %x %x\n\r", _myI2c->CR1, _myI2c->CR2, _myI2c->DR); break; } - /* - else { - ack= _i2c.write(NJU6063_SLAVE, data, 3); - } - */ } +#endif return(ret); } void NJU6063::init(uint8_t chip_addr, uint8_t d) @@ -108,12 +110,12 @@ data[1] = NJU6063_DCHK; data[2] = 0x00; do { - ack = _i2c.write(NJU6063_SLAVE, data, 3); + ack = _i2c.write(NJU6063_SLAVE, data, 3, true); NJU6063_WAIT; timeout--; if (timeout==0) break; } while(!ack); NJU6063_WAIT_MS; } -#endif +//#endif