Author: jsuijs
Date: Sun Sep 28 01:41:05 2008
New Revision: 331
Added:
trunk/unvalidated/sample/test/peripheral/i2c/i2c_test_l0.jal
Modified:
trunk/tools/test_setup/board_16f877a_dwarf.jal
Log:
i2c eeprom read & write works okay on software i2c. Test file included.
Modified: trunk/tools/test_setup/board_16f877a_dwarf.jal
==============================================================================
--- trunk/tools/test_setup/board_16f877a_dwarf.jal (original)
+++ trunk/tools/test_setup/board_16f877a_dwarf.jal Sun Sep 28 01:41:05 2008
@@ -48,9 +48,17 @@
pin_b4_direction = output
pin_b5_direction = output
end procedure
+
+
+var volatile bit i2c_scl is pin_c3
+var volatile bit i2c_scl_direction is pin_c3_direction
+var volatile bit i2c_sda is pin_c4
+var volatile bit i2c_sda_direction is pin_c4_direction
+
+
-- ----------------------------------------------
-- setup end; include generic test programs below
-- ----------------------------------------------
-include test_hello_world_lcd
+;include test_hello_world_lcd
;include test_blink
Added: trunk/unvalidated/sample/test/peripheral/i2c/i2c_test_l0.jal
==============================================================================
--- (empty file)
+++ trunk/unvalidated/sample/test/peripheral/i2c/i2c_test_l0.jal Sun Sep
28
01:41:05 2008
@@ -0,0 +1,70 @@
+--
--------------------------------------------------------------------------
+-- Level 0 i2c TEST file: interact with an i2c eeprom using the i2c
primitives
+--
--------------------------------------------------------------------------
+-- This file defines a test for JALLIB testing, using a test-board
+-- defined by a BOARD file .
+--
+-- setup: an 24lc256 i2c eeprom, connected to the test board i2c pins.
+--
+--
--------------------------------------------------------------------------
+--
+--
--------------------------------------------------------------------------
+
+-- generic setup (see releated examples for more details)
+const usart_hw_serial = true -- true = RS232, false = SPI
+const serial_hw_baudrate = 115_200
+include serial_hardware
+serial_hw_init()
+include print
+include delay_any_mc
+
+-- i2c setup
+const word i2c_bus_speed = 4 ; * 100kHz
+include i2c_software
+; include i2c_hardware
+i2c_initialize()
+
+-- we're alive
+const byte str1[] = "Test.\r\n"
+print_string(serial_hw_data, str1)
+
+var bit r
+var byte i
+forever loop
+
+ -- read first 3 bytes from an 24lc256 eeprom and output these to the
serial port
+ -- then, increment the last one (write one byte)
+ i2c_start()
+ r = i2c_transmit_byte(0xA0) -- i2c address for write (for memory
address, within eeprom)
+ r = r | i2c_transmit_byte(0x00) -- memory address high byte
+ r = r | i2c_transmit_byte(0x00) -- memory address low byte
+
+ i2c_restart()
+ r = r | i2c_transmit_byte(0xA1) -- i2c address for read (of memory from
eeprom)
+
+ i = i2c_receive_byte(true)
+ print_byte_hex(serial_hw_data, i);
+ serial_hw_data = " "
+
+ i = i2c_receive_byte(true)
+ print_byte_hex(serial_hw_data, i);
+ serial_hw_data = " "
+
+ i = i2c_receive_byte(false)
+ print_byte_hex(serial_hw_data, i);
+ serial_hw_data = " "
+
+ i2c_stop()
+
+ i2c_start()
+ r = i2c_transmit_byte(0xA0) -- i2c address for write (for memory
address, within eeprom)
+ r = r | i2c_transmit_byte(0x00) -- memory address high byte
+ r = r | i2c_transmit_byte(0x02) -- memory address low byte
+ r = r | i2c_transmit_byte(i+1) -- data byte
+ i2c_stop()
+
+
+ print_crlf(serial_hw_data)
+
+ delay_100ms(10)
+end loop
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---