File tree 3 files changed +17
-4
lines changed
3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 13
13
14
14
// the sensor communicates using SPI, so include the library:
15
15
#include < SPI.h>
16
+
17
+ /* ******************
18
+ * WEMOS SPI Pins:
19
+ * SCLK - D5
20
+ * MISO - D6
21
+ * MOSI - D7
22
+ * SS - D8
23
+ *******************/
16
24
#include " energyic.h"
17
25
18
26
void setup () {
Original file line number Diff line number Diff line change 71
71
// pins used for the connection with the sensor
72
72
// the other you need are controlled by the SPI library):
73
73
//const int energy_IRQ = 2;
74
- const int energy_CS = 10 ;
74
+ const int energy_CS = D8 ; // WEMOS SS pin
75
75
//const int energy_WO = 8;
76
76
77
77
unsigned short CommEnergyIC (unsigned char RW ,unsigned char address , unsigned short val );
Original file line number Diff line number Diff line change 20
20
unsigned char * data=(unsigned char *)&val;
21
21
unsigned short output;
22
22
// SPI interface rate is 200 to 160k bps. It Will need to be slowed down for EnergyIC
23
- #if !defined(ENERGIA)
23
+ #if !defined(ENERGIA) && !defined(ESP8266)
24
24
SPISettings settings (200000 , MSBFIRST, SPI_MODE3);
25
- #endif
25
+ #endif
26
+
27
+ #if defined(ESP8266)
28
+ SPISettings settings (200000 , MSBFIRST, SPI_MODE2);
29
+ #endif
30
+
26
31
// switch MSB and LSB of value
27
32
output=(val>>8 )|(val<<8 );
28
33
val=output;
35
40
SPI.beginTransaction (settings);
36
41
#endif
37
42
digitalWrite (energy_CS,LOW);
38
- delayMicroseconds (10 );
43
+ delayMicroseconds (10 );
39
44
SPI.transfer (address);
40
45
/* Must wait 4 us for data to become valid */
41
46
delayMicroseconds (4 );
You can’t perform that action at this time.
0 commit comments