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
068abfde
Commit
068abfde
authored
Nov 19, 2015
by
Terry Ellison
Browse files
Merge pull request #781 from marcelstoer/dev-add-hx711-reference
Add reference to HX711 documentation to source
parents
c047d344
6674a7d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/hx711.c
View file @
068abfde
// Module for HX711 load cell amplifier
// https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide
#include "lualib.h"
#include "lualib.h"
#include "lauxlib.h"
#include "lauxlib.h"
#include "platform.h"
#include "platform.h"
...
@@ -32,7 +35,7 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
...
@@ -32,7 +35,7 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
//wakeup hx711
//wakeup hx711
platform_gpio_write
(
clk_pin
,
0
);
platform_gpio_write
(
clk_pin
,
0
);
//wait for data ready. or time out.
//wait for data ready. or time out.
//TODO: set pin inturrupt and come back to it. This may take up to 1/10 sec
//TODO: set pin inturrupt and come back to it. This may take up to 1/10 sec
// or maybe just make an async version too and have both available.
// or maybe just make an async version too and have both available.
...
@@ -40,7 +43,7 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
...
@@ -40,7 +43,7 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
for
(
i
=
0
;
i
<
HX711_MAX_WAIT
&&
platform_gpio_read
(
data_pin
)
==
1
;
i
++
){
for
(
i
=
0
;
i
<
HX711_MAX_WAIT
&&
platform_gpio_read
(
data_pin
)
==
1
;
i
++
){
asm
(
"nop"
);
asm
(
"nop"
);
}
}
//Handle timeout error
//Handle timeout error
if
(
i
>=
HX711_MAX_WAIT
)
{
if
(
i
>=
HX711_MAX_WAIT
)
{
return
luaL_error
(
L
,
"ADC timeout!"
,
(
unsigned
)
0
);
return
luaL_error
(
L
,
"ADC timeout!"
,
(
unsigned
)
0
);
...
@@ -54,14 +57,14 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
...
@@ -54,14 +57,14 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
data
=
i
==
0
?
-
1
:
data
|
1
;
//signextend the first bit
data
=
i
==
0
?
-
1
:
data
|
1
;
//signextend the first bit
}
}
}
}
//add 25th clock pulse to prevent protocol error (probably not needed
//add 25th clock pulse to prevent protocol error (probably not needed
// since we'll go to sleep immediately after and reset on wakeup.)
// since we'll go to sleep immediately after and reset on wakeup.)
platform_gpio_write
(
clk_pin
,
1
);
platform_gpio_write
(
clk_pin
,
1
);
platform_gpio_write
(
clk_pin
,
0
);
platform_gpio_write
(
clk_pin
,
0
);
//sleep
//sleep
platform_gpio_write
(
clk_pin
,
1
);
platform_gpio_write
(
clk_pin
,
1
);
lua_pushinteger
(
L
,
data
);
lua_pushinteger
(
L
,
data
);
return
1
;
return
1
;
}
}
#define MIN_OPT_LEVEL 2
#define MIN_OPT_LEVEL 2
...
...
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