On Mon, Apr 23, 2012 at 1:19 PM, Joep Suijs <[email protected]> wrote:
> Hi guys, > > I am working on a more advanced version of the 24lcxx libs. The name > of the current basic version is eeprom_24lcxxx.jal (e.g. > eeprom_24lc256.jal) > > The things that will be different in the new libraries: > > + page write is supported (up to 128 times faster, my estimate is > sequential filling an 24lc512 takes 2.5 secs instead of 6 minutes) > + advanced handling of required delay-after-write, so no (possible > unnecessary) delay of 5 ms after each write > + more devices supported (2, 4, 8, 32, 64 and 128kx8 are on my list; > don't have all devices to test though). > + success/error indication is propagated back to the user. > - the library uses more resources (flash and ram) > - only one device per application is supported (well... you could use > more, but that is more complex) > > I have two questions: > - Would such a library set be a valuable addition to jallib? > I do not know. But if the following i2c software lib it somehow helps, I've used it some years ago: -- I2C_512 , i2c software library for 24LC256/24LC512 memory -- for jalV2 ver 2.4c may 2008 [email protected] -- based on previous work of: Wouter van Ooijen, Javier Martinez, Ziya Erdemir -- 24C512 device address is 0b_1010_0000 (write address) -- the library is changing automatically the RD/WR bit so -- read address will be 0b_1010_0001 -- both i2c_clock and i2c_data needs pull up resitors according -- to i2c device datasheet, higher frequency means lower resistor values -- WP pin must be connected to GND if you want to program the memory -- this library can work for you with some luck -- having a good scope and understanding before how i2c works will be better -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 of the License, or (at your option) any later version. -- copyright (c) 1999-2008 -- change the following pins for your own design var volatile bit i2c_clock_in is pin_b4 var volatile bit i2c_clock_out is pin_b4_direction var volatile bit i2c_data_in is pin_b1 var volatile bit i2c_data_out is pin_b1_direction procedure _i2c_init is i2c_clock_in = low i2c_clock_out = output i2c_data_in = low i2c_data_out = output end procedure procedure _i2c_wait is _usec_delay ( 5 ) ; adjust for bus speed end procedure -- output a start condition procedure i2c_put_start is _i2c_wait i2c_data_out = high -- data high _i2c_wait i2c_clock_out = high -- clock high _i2c_wait i2c_data_out = low -- data low _i2c_wait i2c_clock_out = low -- clock low _i2c_wait end procedure -- output stop condition procedure i2c_put_stop is _i2c_wait i2c_data_out = low -- data low _i2c_wait i2c_clock_out = low -- clock low _i2c_wait i2c_clock_out = high -- clock high _i2c_wait i2c_data_out = high -- data high _i2c_wait end procedure _i2c_init i2c_put_stop _i2c_wait -- output a single bit (for internal use only) procedure _i2c_bit_out( bit in x ) is _i2c_wait i2c_data_out = x -- high data bit _i2c_wait i2c_clock_out = high -- clock high _i2c_wait while i2c_clock_in == low loop end loop -- wait for slow slave ; _i2c_wait i2c_clock_out = low -- clock low _i2c_wait end procedure -- input a single bit (for internal use only) procedure _i2c_bit_in( bit out x ) is _i2c_wait i2c_data_out = high -- data open _i2c_wait i2c_clock_out = high -- clock high _i2c_wait while i2c_clock_in == low loop end loop -- wait for slow slave ; _i2c_wait x = i2c_data_in -- sample data _i2c_wait i2c_clock_out = low -- clock low _i2c_wait end procedure -- wait for an ack condition -- Return LOW for ACK and HIGH for NACK. function i2c_wait_ack return bit is var bit acktemp _i2c_wait i2c_data_out = high -- data open _i2c_wait i2c_clock_out = high -- clock high _i2c_wait while i2c_clock_in == low loop end loop -- wait for slow slave -- a check for the slave's acknowledge -- (data should be low) -- could be added here acktemp = i2c_data_in -- sample data _i2c_wait i2c_clock_out = low -- clock low _i2c_wait return acktemp end function -- output an ack condition procedure i2c_put_ack is _i2c_bit_out( low ) end procedure -- output a nack condition procedure i2c_put_nack is _i2c_bit_out( high ) end procedure -- output one byte procedure i2c_put_data( byte in x ) is var bit b at x : 7 for 8 loop _i2c_bit_out( b ) x = x << 1 end loop end procedure -- input one byte procedure i2c_get_data( byte out x ) is var bit b at x : 0 for 8 loop x = x << 1 _i2c_bit_in( b ) end loop end procedure -- address I2c device function i2c_put_write_address( byte in x ) return bit is i2c_put_start i2c_put_data ( x ) return i2c_wait_ack end function function i2c_put_read_address( byte in x ) return bit is i2c_put_start i2c_put_data ( x + 0b_0000_0001 ) return i2c_wait_ack end function -- two byte address version procedure i2c_wr_512( byte in dev_adr, byte in adr_hi, byte in adr_lo, byte in data ) is while i2c_put_write_address( dev_adr ) loop ; only for debug purposes i2c_put_stop end loop ; i2c_put_write_address( dev_adr ) i2c_put_data( adr_hi ) i2c_wait_ack i2c_put_data( adr_lo ) i2c_wait_ack i2c_put_data( data ) i2c_wait_ack i2c_put_stop end procedure -- two byte address version procedure i2c_rd_512( byte in dev_adr, byte in adr_hi, byte in adr_lo , byte out data) is while i2c_put_write_address( dev_adr ) loop ; only for debug purposes i2c_put_stop end loop ; i2c_put_write_address( dev_adr ) i2c_put_data( adr_hi ) i2c_put_ack i2c_put_data( adr_lo ) i2c_put_ack i2c_put_read_address( dev_adr ) i2c_get_data( data ) i2c_put_nack i2c_put_stop end procedure -- one word address version procedure i2c_wr_512w( byte in dev_adr, byte*2 in adr, byte in data ) is var byte adr_lohi [2] at adr while i2c_put_write_address( dev_adr ) loop ; only for debug purposes i2c_put_stop end loop ; i2c_put_write_address( dev_adr ) i2c_put_data( adr_lohi [1] ) ; hi byte i2c_wait_ack i2c_put_data( adr_lohi [0] ) ; lo byte i2c_wait_ack i2c_put_data( data ) i2c_wait_ack i2c_put_stop end procedure -- one word address version procedure i2c_rd_512w( byte in dev_adr, byte*2 in adr, byte out data) is var byte adr_lohi [2] at adr while i2c_put_write_address( dev_adr ) loop ; only for debug purposes i2c_put_stop end loop ; i2c_put_write_address( dev_adr ) i2c_put_data( adr_lohi [1] ) ; hi_byte i2c_put_ack i2c_put_data( adr_lohi [0] ) ; lo_byte i2c_put_ack i2c_put_read_address( dev_adr ) i2c_get_data( data ) i2c_put_nack i2c_put_stop end procedure -- You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jallib?hl=en.
