Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I2C LCD + Keypad - Adafruit 715
06-01-2014, 05:39 PM,
#11
RE: I2C LCD + Keypad - Adafruit 715
(06-01-2014, 04:14 PM)regis Wrote: Of course you can modified the i2c library as long as you take care of regression issues.
I will try to help you if I can.


(06-01-2014, 02:34 PM)charlie_abb Wrote: Hi Regis,
I checked out the I2C and LCDI2C libraries. The LCDI2C library uses a PCF8574 I2C expander which only requires 1 byte to be written or read at any time. The I2C library is also only written to send or receive 1 byte of data at a time. I will be using the MCP23017 device which is looking for |Op code (incl hardware addy)| Register addy | Data to write/read |. Can the I2C library be modified (as suggested by RL) to write/read more than 1 byte at a time so that I can write/read to the MCP23017 by passing the register addy before the data byte? Your help would be appreciated.

Have a look in the folder Examples/04 Communication/I2C at DS1307serial.pde and inside this pde at the function :
u8 DS1307_send_receive(u8 address, u8 *wbuffer, u8 wlength, u8 *rbuffer, u8 rlength).
Therefore the library is not exactly limited at a byte. You can certainly modify this function and adapt it to your project.
Reply
07-01-2014, 06:17 PM,
#12
RE: I2C LCD + Keypad - Adafruit 715
Hi Regis
I have worked through the LCDI2C libraries and am modding them for the MCP23017 expander chip - so far no big problems - BUT I have found that the Adafruit LCD + Keypad shield has the 4 Data bits for the LCD DB4-7 connected to pins GPB 4-0 - that is the bits are reversed (not sure why they have connected it this way. To send the data bits to the LCD I will have to rotate the 8 bits of the byte and then mask it - can you tell me how to do this in C on the IDE or in GCC MIPS assembler?
Thanks.
Reply
07-01-2014, 08:37 PM,
#13
RE: I2C LCD + Keypad - Adafruit 715
Er "pins 4-7 ... 4-0" can't be right as it would mean 4 pins and 5 pins.

For 4 pins it's just 16 values so an array is easy.

John
Reply
08-01-2014, 10:19 AM,
#14
RE: I2C LCD + Keypad - Adafruit 715
Hm, are you sure the pins are actually mirrored? This may be sort of a mis-interpretation, different counting scheme notation, possibly resulting from different documents/sources? Please reassure!

I think John points out that the easiest and fastest way to do the [back/forth] mirroring would be a look-up-table like this (count binary from 0 to 15, just reversing the normal bit writing direction):
const char mir4bits[] =
{0, 0b1000, 0b0100, 0b1100, 0b0010, 0b1010, 0b0110, 0b1110, 0b0001, 0b1001, 0b0101, 0b1101, 0b0011, 0b1011, 0b0111, 0b1111};
or
{0,8,4, 8+4, 2, 8+2, 4+2, 15-1, 1, 1+8, 1+4, 15-2, 1+2, 15-4, 15-8, 15};
Reply
08-01-2014, 02:37 PM,
#15
RE: I2C LCD + Keypad - Adafruit 715
Correction - should read pins 3-0. Thanks for suggestion on mirroring.
Reply
08-01-2014, 04:18 PM,
#16
RE: I2C LCD + Keypad - Adafruit 715
Just checking the LCDI2C code -

LCD_EN = LOW;
I2C_send(I2C1, PCF8574_address, PCF8574_data.val);
Delayus(1);// E Enable Cycle > (300 + 200) = 500ns

Is LCD_EN a macro which directly writes to the EN pin on the PCF8574 and, if so, in which file is it?
Reply
08-01-2014, 04:24 PM, (This post was last modified: 08-01-2014, 04:24 PM by pingotg.)
#17
RE: I2C LCD + Keypad - Adafruit 715
Looks to be in
p32/include/pinguino/libraries/lcdi2c.h

On Linux you can do searches like:
find -name '*.[ch]' -print0 | xargs -0 grep LCD_EN | less

If on Windows, you can install Linux-type tools Smile

John
Reply
08-01-2014, 06:40 PM,
#18
RE: I2C LCD + Keypad - Adafruit 715
OK thanks but I checked on lcdi2c.h and it has the entry " #define LCD_EN PCF8574_data.bits.P3 // P3" - so how does the entry
LCD_EN = LOW;
I2C_send(I2C1, PCF8574_address, PCF8574_data.val);
Delayus(1);// E Enable Cycle > (300 + 200) = 500ns
in lcdi2c.c set the LCD_EN pin low?
Apologies if its a dumb question but I am still learning!
Reply
08-01-2014, 06:54 PM,
#19
RE: I2C LCD + Keypad - Adafruit 715
in lcdi2c.h : #include <pcf8574.h>
in pcf8574.h :

Code:
    typedef union
    {
        u8 val;
        struct
        {
            unsigned P0 :1;
            unsigned P1 :1;
            unsigned P2 :1;
            unsigned P3 :1;
            unsigned P4 :1;
            unsigned P5 :1;
            unsigned P6 :1;
            unsigned P7 :1;
        } bits;
    } PCF8574_t;

Wink
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
08-01-2014, 07:07 PM,
#20
RE: I2C LCD + Keypad - Adafruit 715
A union is a kind of doubly-named (or multiply-named) thing. So the LCD_EN = ... is setting a bit in the union. In this case bits and val are the same thing (a byte, here, as that's the size of u8 and also of that struct bits).

Then the I2C_send outputs the whole thing.

It's relying on the order of bits which in portable C would be terrible but this isn't portable C.

John
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)