My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- Title: Master part of i2c slave echo
-- 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 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 by jallib.py from:
-- * board: board_16f88_js.jal
-- * test : test_i2c_sw_master_echo.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() -- make all pins digital I/O
;@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()

const single_byte_tx_buffer = 1
var byte i2c_tx_buffer[1]
var byte i2c_rx_buffer[1]
include i2c_level1


-- generic setup (see releated examples for more details);@jallib section serial
const serial_hw_baudrate = 115_200
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

Change log

r3043 by jsuijs on Apr 22, 2012   Diff
regenerated samples with 'generated by
jallib.py' to detect outdated samples.
Go to: 
Project members, sign in to write a code review

Older revisions

r2811 by jsuijs on Oct 15, 2011   Diff
updated libs
r2760 by sebastien.lelong on Jul 31, 2011   Diff
added Revision: field + svn:keywords
Revision property on all existing
*.jal files. Also add to normalize EOL
chars to avoid mixed ones
r2278 by jsuijs on Oct 20, 2010   Diff
enable_digital_io() for i2c sw samples
All revisions of this file

File info

Size: 3594 bytes, 103 lines

File properties

svn:keywords
Revision
Powered by Google Project Hosting