-- 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.4m -- Revision: $Revision$ -- -- 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: -- -- -- This file has been generated by jallib.py from: -- * board: board_16f88_js.jal -- * test : test_i2c_hw_slave_check_bus.jal -- ;@jallib section chipdef -- chip setup include 16f88 ;-- ;-- This setup assumes a 20 MHz resonator or crystal ;-- is connected to pins OSC1 and OSC2. pragma target OSC HS -- HS crystal or resonator pragma target clock 20_000_000 -- oscillator frequency pragma target WDT disabled -- no watchdog pragma target LVP disabled -- no low-voltage programming pragma target CCP1MUX pin_B3 -- ccp1 pin on B3 -- -- This setup uses the internal oscillator ;pragma target OSC INTOSC_NOCLKOUT -- HS crystal or resonator ;pragma target clock 8_000_000 -- oscillator frequency ;pragma target WDT disabled -- no watchdog ;pragma target LVP disabled -- no low-voltage programming ;pragma target CCP1MUX pin_B3 -- ccp1 pin on B3 ;OSCCON_IRCF = 7 -- set prescaler to 1 (8 MHz) enable_digital_io() ;@jallib section led -- LED IO definition alias led is pin_b3 alias led_direction is pin_b3_direction alias led2 is pin_b1 alias led2_direction is pin_b1_direction -- i2c setup -- with Start/Stop interrupts const bit i2c_enable_start_stop_interrupts = true 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) -- 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 -- 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