@@ -267,7 +267,7 @@ void LiquidCrystal_PCF8574::createChar_P(uint8_t location, const byte *charmap)
267
267
byte c = pgm_read_byte (p++);
268
268
write (c);
269
269
}
270
- } // createCharPgm ()
270
+ } // createChar_P ()
271
271
#endif
272
272
273
273
@@ -282,33 +282,58 @@ inline size_t LiquidCrystal_PCF8574::write(uint8_t ch)
282
282
// write either command or data
283
283
void LiquidCrystal_PCF8574::_send (uint8_t value, bool isData)
284
284
{
285
+ // An I2C transmission has a significant overhead of ~10+1 I2C clock
286
+ // cycles. We consequently only perform it only once per _send().
287
+
288
+ Wire.beginTransmission (_i2cAddr);
285
289
// write high 4 bits
286
- _sendNibble ((value >> 4 & 0x0F ), isData);
290
+ _writeNibble ((value >> 4 & 0x0F ), isData);
287
291
// write low 4 bits
288
- _sendNibble ((value & 0x0F ), isData);
292
+ _writeNibble ((value & 0x0F ), isData);
293
+ Wire.endTransmission ();
289
294
} // _send()
290
295
291
296
292
297
// write a nibble / halfByte with handshake
293
- void LiquidCrystal_PCF8574::_sendNibble (uint8_t halfByte, bool isData)
298
+ void LiquidCrystal_PCF8574::_writeNibble (uint8_t halfByte, bool isData)
294
299
{
295
300
// map the data to the given pin connections
296
- uint8_t data = 0 ;
301
+ uint8_t data = isData ? _rs_mask : 0 ;
302
+ // _rw_mask is not used here.
303
+ if (_backlight > 0 )
304
+ data |= _backlight_mask;
297
305
298
306
// allow for arbitrary pin configuration
299
307
if (halfByte & 0x01 ) data |= _data_mask[0 ];
300
308
if (halfByte & 0x02 ) data |= _data_mask[1 ];
301
309
if (halfByte & 0x04 ) data |= _data_mask[2 ];
302
310
if (halfByte & 0x08 ) data |= _data_mask[3 ];
303
311
304
- _write2Wire (data, isData, true );
305
- delayMicroseconds (1 ); // enable pulse must be >450ns
306
- _write2Wire (data, isData, false );
307
- delayMicroseconds (37 ); // commands need > 37us to settle
312
+ // Note that the specified speed of the PCF8574 chip is 100KHz.
313
+ // Transmitting a single byte takes 9 clock ticks at 100kHz -> 90us.
314
+ // The 37us delay is only necessary after sending the second nibble.
315
+ // But in that case we have to restart the transfer using additional
316
+ // >10 clock cycles. Hence, no additional delays are necessary even
317
+ // when the I2C bus is operated beyond the chip's spec in fast mode
318
+ // at 400 kHz.
319
+
320
+ Wire.write (data | _enable_mask);
321
+ // delayMicroseconds(1); // enable pulse must be >450ns
322
+ Wire.write (data);
323
+ // delayMicroseconds(37); // commands need > 37us to settle
324
+ } // _writeNibble
325
+
326
+
327
+ // write a nibble / halfByte with handshake
328
+ void LiquidCrystal_PCF8574::_sendNibble (uint8_t halfByte, bool isData)
329
+ {
330
+ Wire.beginTransmission (_i2cAddr);
331
+ _writeNibble (halfByte, isData);
332
+ Wire.endTransmission ();
308
333
} // _sendNibble
309
334
310
335
311
- // private function to change the PCF8674 pins to the given value
336
+ // private function to change the PCF8574 pins to the given value
312
337
void LiquidCrystal_PCF8574::_write2Wire (uint8_t data, bool isData, bool enable)
313
338
{
314
339
if (isData)
0 commit comments