Skip to content

Commit 5b85806

Browse files
committed
SPI mode now works with Wemos, weird conditional compile due to esp8266/Arduino#2270
1 parent 6296650 commit 5b85806

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

ATM90E26.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313

1414
// the sensor communicates using SPI, so include the library:
1515
#include <SPI.h>
16+
17+
/*******************
18+
* WEMOS SPI Pins:
19+
* SCLK - D5
20+
* MISO - D6
21+
* MOSI - D7
22+
* SS - D8
23+
*******************/
1624
#include "energyic.h"
1725

1826
void setup() {

energyic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
// pins used for the connection with the sensor
7272
// the other you need are controlled by the SPI library):
7373
//const int energy_IRQ = 2;
74-
const int energy_CS = 10;
74+
const int energy_CS = D8; // WEMOS SS pin
7575
//const int energy_WO = 8;
7676

7777
unsigned short CommEnergyIC(unsigned char RW,unsigned char address, unsigned short val);

energyic.ino

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
unsigned char* data=(unsigned char*)&val;
2121
unsigned short output;
2222
//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)
2424
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+
2631
//switch MSB and LSB of value
2732
output=(val>>8)|(val<<8);
2833
val=output;
@@ -35,7 +40,7 @@
3540
SPI.beginTransaction(settings);
3641
#endif
3742
digitalWrite (energy_CS,LOW);
38-
delayMicroseconds(10);
43+
delayMicroseconds(10);
3944
SPI.transfer(address);
4045
/* Must wait 4 us for data to become valid */
4146
delayMicroseconds(4);

0 commit comments

Comments
 (0)