Skip to content

Commit c5a8e8c

Browse files
Zardshardmarcelstoer
authored andcommitted
Fix SH1106Spi.h not using chip select pin
1 parent 041ba32 commit c5a8e8c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/SH1106Spi.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,20 @@ class SH1106Spi : public OLEDDisplay {
3838
private:
3939
uint8_t _rst;
4040
uint8_t _dc;
41+
uint8_t _cs;
4142

4243
public:
4344
SH1106Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
4445
setGeometry(g);
4546

4647
this->_rst = _rst;
4748
this->_dc = _dc;
49+
this->_cs = _cs;
4850
}
4951

5052
bool connect(){
5153
pinMode(_dc, OUTPUT);
54+
pinMode(_cs, OUTPUT);
5255
pinMode(_rst, OUTPUT);
5356

5457
SPI.begin ();
@@ -102,21 +105,27 @@ class SH1106Spi : public OLEDDisplay {
102105
sendCommand(0xB0 + y);
103106
sendCommand(minBoundXp2H);
104107
sendCommand(minBoundXp2L);
108+
digitalWrite(_cs, HIGH);
105109
digitalWrite(_dc, HIGH); // data mode
110+
digitalWrite(_cs, LOW);
106111
for (x = minBoundX; x <= maxBoundX; x++) {
107112
SPI.transfer(buffer[x + y * displayWidth]);
108113
}
114+
digitalWrite(_cs, HIGH);
109115
yield();
110116
}
111117
#else
112118
for (uint8_t y=0; y<displayHeight/8; y++) {
113119
sendCommand(0xB0 + y);
114120
sendCommand(0x02);
115121
sendCommand(0x10);
122+
digitalWrite(_cs, HIGH);
116123
digitalWrite(_dc, HIGH); // data mode
124+
digitalWrite(_cs, LOW);
117125
for( uint8_t x=0; x < displayWidth; x++) {
118126
SPI.transfer(buffer[x + y * displayWidth]);
119127
}
128+
digitalWrite(_cs, HIGH);
120129
yield();
121130
}
122131
#endif
@@ -127,8 +136,11 @@ class SH1106Spi : public OLEDDisplay {
127136
return 0;
128137
}
129138
inline void sendCommand(uint8_t com) __attribute__((always_inline)){
139+
digitalWrite(_cs, HIGH);
130140
digitalWrite(_dc, LOW);
141+
digitalWrite(_cs, LOW);
131142
SPI.transfer(com);
143+
digitalWrite(_cs, HIGH);
132144
}
133145
};
134146

0 commit comments

Comments
 (0)