-- Title: Master part of i2c slave check bus test -- 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 test corresponds to the master part -- of i2c hardware slave bus check testing program. It blinks a little, -- then send a i2c command, then infinitely loop. -- This is a one-shot test, if you want to run it again, reset your PICs -- (or switch the power off/on...) -- -- Sources: -- -- -- This file has been generated by jallib.py from: -- * board: board_16f88_js.jal -- * test : test_i2c_sw_master_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 -- blink a little, then send i2c command led_direction = output for 8 loop led = on _usec_delay(250000) led = off _usec_delay(250000) end loop ;@jallib section i2c -- I2C io definition alias i2c_scl is pin_b4 alias i2c_scl_direction is pin_b4_direction -- b3 is pin-compatible with 16f648a board file, b1 is on hardware pins ;alias i2c_sda is pin_b3 ;alias i2c_sda_direction is pin_b3_direction alias i2c_sda is pin_b1 alias 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 var byte icaddress = 0x1F -- slave address, can be anything -- go! If slave starts to flash at high speed, -- it works ! -- dummy command i2c_tx_buffer[0] = "." var bit _trash = i2c_send_receive(icaddress, 1, 1) forever loop -- reached the end of test end loop