Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
7095c424
Commit
7095c424
authored
Aug 22, 2015
by
aeprox
Browse files
Attempt to fix reading of registers
parent
159e9c6a
Changes
2
Show whitespace changes
Inline
Side-by-side
app/tsl2561/tsl2561.c
View file @
7095c424
/**************************************************************************/
/**************************************************************************/
/*!
/*!
@file tsl2561.c
@file tsl2561.c
@author K. Townsend (microBuilder.eu)
@author K. Townsend (microBuilder.eu)
/ Adapted for nodeMCU by Michael Lucas (Aeprox @github)
@brief Drivers for the TAOS TSL2561 I2C digital luminosity sensor
@brief Drivers for the TAOS TSL2561 I2C digital luminosity sensor
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
uint32_t lux;
uint32_t lux;
// Initialise luminosity sensor
// Initialise luminosity sensor
tsl2561Init();
tsl2561Init(
sda_pin, scl_pin
);
// Optional ... default setting is 400ms with no gain
// Optional ... default setting is 400ms with no gain
// Set timing to 101ms with no gain
// Set timing to 101ms with no gain
...
@@ -100,18 +100,20 @@ tsl2561Error_t tsl2561Read16(uint8_t reg, uint16_t *value)
...
@@ -100,18 +100,20 @@ tsl2561Error_t tsl2561Read16(uint8_t reg, uint16_t *value)
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_TRANSMITTER
);
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_TRANSMITTER
);
platform_i2c_send_byte
(
tsl2561_i2c_id
,
reg
);
platform_i2c_send_byte
(
tsl2561_i2c_id
,
reg
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
platform_i2c_send_start
(
tsl2561_i2c_id
);
platform_i2c_send_start
(
tsl2561_i2c_id
);
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_RECEIVER
);
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_RECEIVER
);
uint8_t
ch_
high
=
platform_i2c_recv_byte
(
tsl2561_i2c_id
,
0
);
uint8_t
ch_
low
=
platform_i2c_recv_byte
(
tsl2561_i2c_id
,
0
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
platform_i2c_send_start
(
tsl2561_i2c_id
);
platform_i2c_send_start
(
tsl2561_i2c_id
);
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_TRANSMITTER
);
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_TRANSMITTER
);
platform_i2c_send_byte
(
tsl2561_i2c_id
,
reg
);
platform_i2c_send_byte
(
tsl2561_i2c_id
,
reg
+
1
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
platform_i2c_send_start
(
tsl2561_i2c_id
);
platform_i2c_send_start
(
tsl2561_i2c_id
);
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_RECEIVER
);
platform_i2c_send_address
(
tsl2561_i2c_id
,
TSL2561_ADDRESS
,
PLATFORM_I2C_DIRECTION_RECEIVER
);
uint8_t
ch_
low
=
platform_i2c_recv_byte
(
tsl2561_i2c_id
,
0
);
uint8_t
ch_
high
=
platform_i2c_recv_byte
(
tsl2561_i2c_id
,
0
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
platform_i2c_send_stop
(
tsl2561_i2c_id
);
// Shift values to create properly formed integer (low byte first)
// Shift values to create properly formed integer (low byte first)
...
@@ -181,7 +183,7 @@ tsl2561Error_t tsl2561SetTiming(tsl2561IntegrationTime_t integration, tsl2561Gai
...
@@ -181,7 +183,7 @@ tsl2561Error_t tsl2561SetTiming(tsl2561IntegrationTime_t integration, tsl2561Gai
error
=
tsl2561Enable
();
error
=
tsl2561Enable
();
if
(
error
)
return
error
;
if
(
error
)
return
error
;
//
Turn the device off to save power
//
set timing and gain on device
error
=
tsl2561Write8
(
TSL2561_COMMAND_BIT
|
TSL2561_REGISTER_TIMING
,
integration
|
gain
);
error
=
tsl2561Write8
(
TSL2561_COMMAND_BIT
|
TSL2561_REGISTER_TIMING
,
integration
|
gain
);
if
(
error
)
return
error
;
if
(
error
)
return
error
;
...
...
app/tsl2561/tsl2561.h
View file @
7095c424
/**************************************************************************/
/**************************************************************************/
/*!
/*!
@file tsl2561.h
@file tsl2561.h
@author K. Townsend (microBuilder.eu)
@author K. Townsend (microBuilder.eu)
/ Adapted for nodeMCU by Michael Lucas (Aeprox @github)
@section LICENSE
@section LICENSE
Software License Agreement (BSD License)
Software License Agreement (BSD License)
Copyright (c) 2010, microBuilder SARL
Copyright (c) 2010, microBuilder SARL
/ Adapted for nodeMCU by Michael Lucas (Aeprox @github)
All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
#define TSL2561_PACKAGE_CS // Lux calculations differ slightly for CS package
#define TSL2561_PACKAGE_CS // Lux calculations differ slightly for CS package
// #define TSL2561_PACKAGE_T_FN_CL
// #define TSL2561_PACKAGE_T_FN_CL
#define TSL2561_ADDRESS (0x
72
) //
0111001 shifted left 1 bit = 0x72 (ADDR = GND or floating)
#define TSL2561_ADDRESS (0x
39
) //
or 0x29, or 0x49
#define TSL2561_READBIT (0x01)
#define TSL2561_READBIT (0x01)
#define TSL2561_COMMAND_BIT (0x80) // Must be 1
#define TSL2561_COMMAND_BIT (0x80) // Must be 1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment