summaryrefslogtreecommitdiffhomepage
path: root/digital/dev2/doc/twi.txt
blob: 3478b4924673c591560e61df357ea6751e5cd0d9 (plain)
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
=====================================
 dev2 twi - Two Wire Interface (I2C)
=====================================

The twi module provides a master twi controlled by the host.

Do not forget to select an output using the control script!

Controlling using a serial monitor
==================================

To control twi master, use a serial monitor (minicom, picocom, gtkterm,
screen, socat...).  This module defines a language to make twi requests.

Commands are composed of a command letter, followed by hexadecimal parameters,
and finally a carriage return.

Protocol errors are signaled using an exclamation mark followed by a carriage
return.

Sending data
------------

Command::

    s<slave><data string>\r

Response::

    S<number of bytes sent>\r

For example::

    s04010203\r
    S03\r

The example sends the bytes 0x01, 0x02 and 0x03 to the slave at address 0x04.
The modules responded that all three bytes were sent.

Receiving data
--------------

Command::

    r<slave><number of bytes to receive>\r

Response::

    R<data string>\r

For example::

    r0403\r
    R010203\r

The example request to read three bytes from the slave at address 0x04.  The
modules responded with the received data.

Controlling using python
========================

The `dev2.twi` python modules defines the Twi class to easily access the twi
module.