Author: sebastien.lelong
Date: Sat Jan 17 03:48:00 2009
New Revision: 733
Added:
trunk/sample/test/peripheral/i2c/test_i2c_check_bus.jal
Modified:
trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_echo.jal
Log:
i2c hw slave: one-shot testing program to check i2c bus in a hardware point
of view. Slave side
Added: trunk/sample/test/peripheral/i2c/test_i2c_check_bus.jal
==============================================================================
--- (empty file)
+++ trunk/sample/test/peripheral/i2c/test_i2c_check_bus.jal Sat Jan 17
03:48:00 2009
@@ -0,0 +1,77 @@
+-- Title: Program to test an i2c bus (using i2c hardware slave)
+-- 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 is a one shot test program. It's used to check if
+-- i2c bus is properly operational. It requires an SSP/i2c enabled PIC
+-- --
+-- The idea is enable Start/Stop interrupts. When master sends something,
whatever
+-- the address, it should produce an interrupt on this slave. As soon as
interrupt
+-- is dealt with, a LED is flashing indefinitely (it also slowly blink
when PIC is up)
+--
+-- Sources:
+--
+
+;@jallib use chipdef
+enable_digital_io()
+
+;@jallib use led
+
+-- ok, now setup serial
+const usart_hw_serial = true -- true = RS232, false = SPI
+;@jallib use serial
+include serial_hardware
+serial_hw_init()
+
+
+-- i2c setup
+include i2c_hw_slave
+const SLAVE_ADDRESS = 0x23 -- whatever, it's not important, and can be
+ -- different from the
address the master wants
+ -- to talk to
+-- this init automatically sets global/peripherals interrupts
+i2c_hw_slave_init(SLAVE_ADDRESS,true) -- with Start/Stop interrupts
+
+
+-- Main ISR
+procedure i2c_isr() is
+ pragma interrupt
+ if ! PIR1_SSPIF then
+ return
+ end if
+ -- reset flag
+ PIR1_SSPIF = false
+ -- tmp store SSPSTAT and mask out unimportant bit
+ var byte tmpstat
+ tmpstat = SSPSTAT
+ -- debug
+ serial_hw_write(tmpstat)
+ -- check start signals
+ if (tmpstat == 0b_1000) then
+ -- If we get there, this means this is an SSP/I2C interrupts
+ -- and this means i2c bus is properly operational !!!
+ while true loop
+ led = on
+ _usec_delay(100000)
+ led = off
+ _usec_delay(100000)
+ end loop
+ end if
+end procedure
+
+-- Blink a little when PIC is up
+led_direction = output
+for 4 loop
+ led = on
+ _usec_delay(250000)
+ led = off
+ _usec_delay(250000)
+end loop
+
+-- waiting for interrupts
+forever loop
+end loop
Modified: trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_echo.jal
==============================================================================
--- trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_echo.jal (original)
+++ trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_echo.jal Sat Jan 17
03:48:00 2009
@@ -24,7 +24,6 @@
-- tell the world we're ready
serial_hw_write("!")
-;@jallib use i2c
include i2c_hw_slave
-- this will be the slave address. It looks like:
-- 0b_0101_1100
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---