Skip to content

Commit 6761962

Browse files
committed
Added Energia support
1 parent 8f7d912 commit 6761962

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

energyic.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
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)
2324
SPISettings settings(200000, MSBFIRST, SPI_MODE3);
24-
25+
#endif
2526
//switch MSB and LSB of value
2627
output=(val>>8)|(val<<8);
2728
val=output;
@@ -30,9 +31,11 @@
3031
address|=RW<<7;
3132

3233
//Transmit and receive data
34+
#if !defined(ENERGIA)
3335
SPI.beginTransaction(settings);
36+
#endif
3437
digitalWrite (energy_CS,LOW);
35-
delayMicroseconds(10);
38+
delayMicroseconds(10);
3639
SPI.transfer(address);
3740
/* Must wait 4 us for data to become valid */
3841
delayMicroseconds(4);
@@ -60,7 +63,9 @@
6063

6164
digitalWrite(energy_CS,HIGH);
6265
delayMicroseconds(10);
66+
#if !defined(ENERGIA)
6367
SPI.endTransaction();
68+
#endif
6469

6570
output=(val>>8)|(val<<8); //reverse MSB and LSB
6671
return output;
@@ -122,9 +127,15 @@ void InitEnergyIC(){
122127
pinMode(energy_IRQ,INPUT );
123128
pinMode(energy_CS,OUTPUT );
124129
pinMode(energy_WO,INPUT );
125-
130+
126131
/* Enable SPI */
127132
SPI.begin();
133+
#if defined(ENERGIA)
134+
SPI.setBitOrder(MSBFIRST);
135+
SPI.setDataMode(SPI_MODE3);
136+
SPI.setClockDivider(SPI_CLOCK_DIV16);
137+
#endif
138+
128139

129140
CommEnergyIC(0,SoftReset,0x789A); //Perform soft reset
130141
CommEnergyIC(0,FuncEn,0x0030); //Voltage sag irq=1, report on warnout pin=1, energy dir change irq=0

0 commit comments

Comments
 (0)