Author: sebastien.lelong
Date: Sun Jan 4 02:42:45 2009
New Revision: 720
Added:
trunk/sample/by_device/16f88/16f88_i2c_sw_master_echo.jal
trunk/sample/test/peripheral/i2c/test_i2c_sw_master_echo.jal
Log:
i2c sw master echo test + sample for 16f88, this is the master side of i2c
hw slave echo test
Added: trunk/sample/by_device/16f88/16f88_i2c_sw_master_echo.jal
==============================================================================
--- (empty file)
+++ trunk/sample/by_device/16f88/16f88_i2c_sw_master_echo.jal Sun Jan 4
02:42:45 2009
@@ -0,0 +1,87 @@
+-- Title: Master part of i2c slave echo
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this test corresponds to the master part
+-- of i2c hardware slave echo test (test_i2c_hardware_slave_echo.jal)
+-- While the slave is an hardare i2c, this master uses i2c software,
+-- so it can be run on any PIC.
+-- --
+-- Basically, this test collects chars from a PC via a serial link,
+-- and sends them to the i2c slave. It then reads the results from the
slave.
+-- Since the slave is supposed to echo the char + 1, if you type "a", you
should
+-- get "b". How great :)
+--
+-- Sources:
+----
+-- This file has been generated on Sun Jan 4 11:40:34 2009, from:
+-- * board: board_16f88_sl.jal
+-- * test : test_i2c_sw_master_echo.jal
+--
+;@jallib section chipdef
+-- chip setup
+include 16f88
+
+;--
+-- We'll use internal oscillator. It work @ 8MHz
+pragma target clock 8_000_000
+pragma target OSC INTOSC_NOCLKOUT
+-- Specify no postscaler, ie. really runs @8MHz
+OSCCON_IRCF = 0b_111
+pragma target WDT disabled -- no watchdog
+pragma target LVP disabled -- no low-voltage programming
+pragma target CCP1MUX RB0 -- ccp1 pin on B0
+pragma bootloader long_start -- for TinyBootloader
+
+;@jallib section i2c
+-- I2C io definition
+var volatile bit i2c_scl is pin_b4
+var volatile bit i2c_scl_direction is pin_b4_direction
+var volatile bit i2c_sda is pin_b1
+var volatile bit i2c_sda_direction is pin_b1_direction
+-- i2c setup
+const word _i2c_bus_speed = 4 ; 400kHz
+const bit _i2c_level = true ; i2c levels (not SMB)
+include i2c_software
+i2c_initialize()
+
+var byte i2c_tx_buffer[2]
+var byte i2c_rx_buffer[1]
+include i2c_level1
+
+
+-- generic setup (see releated examples for more details)
+const usart_hw_serial = true -- true = RS232, false = SPI;@jallib section
serial
+const serial_hw_baudrate = 57_600
+include serial_hardware
+serial_hw_init()
+-- Tell the world we're ready !
+serial_hw_write("!")
+
+
+var byte pc_char
+var byte ic_char
+-- Slave address, 8-bits long
+-- The LSb bit is corresponding to read/write operation
+-- It can be either 0 or 1, since it's the i2c library
+-- which will handle this, not you !
+-- Note: must be exactly the same as in slave's code
+var byte icaddress = 0x5C -- slave address
+
+forever loop
+ if serial_hw_read(pc_char)
+ then
+ serial_hw_write(pc_char) -- echo
+ -- transmit to slave
+ -- we want to send 1 byte, and receive 1 from the slave
+ i2c_tx_buffer[0] = pc_char
+ var bit _trash = i2c_send_receive(icaddress, 1, 1)
+ -- receive buffer should contain our result
+ ic_char = i2c_rx_buffer[0]
+ serial_hw_write(ic_char)
+ end if
+end loop
Added: trunk/sample/test/peripheral/i2c/test_i2c_sw_master_echo.jal
==============================================================================
--- (empty file)
+++ trunk/sample/test/peripheral/i2c/test_i2c_sw_master_echo.jal Sun Jan
4
02:42:45 2009
@@ -0,0 +1,66 @@
+-- Title: Master part of i2c slave echo
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this test corresponds to the master part
+-- of i2c hardware slave echo test (test_i2c_hardware_slave_echo.jal)
+-- While the slave is an hardare i2c, this master uses i2c software,
+-- so it can be run on any PIC.
+-- --
+-- Basically, this test collects chars from a PC via a serial link,
+-- and sends them to the i2c slave. It then reads the results from the
slave.
+-- Since the slave is supposed to echo the char + 1, if you type "a", you
should
+-- get "b". How great :)
+--
+-- Sources:
+--
+
+;@jallib use chipdef
+
+;@jallib use i2c
+-- i2c setup
+const word _i2c_bus_speed = 4 ; 400kHz
+const bit _i2c_level = true ; i2c levels (not SMB)
+include i2c_software
+i2c_initialize()
+
+var byte i2c_tx_buffer[2]
+var byte i2c_rx_buffer[1]
+include i2c_level1
+
+
+-- generic setup (see releated examples for more details)
+const usart_hw_serial = true -- true = RS232, false = SPI
+;@jallib use serial
+include serial_hardware
+serial_hw_init()
+-- Tell the world we're ready !
+serial_hw_write("!")
+
+
+var byte pc_char
+var byte ic_char
+-- Slave address, 8-bits long
+-- The LSb bit is corresponding to read/write operation
+-- It can be either 0 or 1, since it's the i2c library
+-- which will handle this, not you !
+-- Note: must be exactly the same as in slave's code
+var byte icaddress = 0x5C -- slave address
+
+forever loop
+ if serial_hw_read(pc_char)
+ then
+ serial_hw_write(pc_char) -- echo
+ -- transmit to slave
+ -- we want to send 1 byte, and receive 1 from the slave
+ i2c_tx_buffer[0] = pc_char
+ var bit _trash = i2c_send_receive(icaddress, 1, 1)
+ -- receive buffer should contain our result
+ ic_char = i2c_rx_buffer[0]
+ serial_hw_write(ic_char)
+ end if
+end loop
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---