@@ -8,27 +8,47 @@ deadlock situations, it allows for communication using a repeated start
88condition as required by some devices, the code is much more compact and the
99structure is easier to understand.
1010
11- The current state of the port is quite incomplete. Missing parts:
1211
13- - read functions
14- - speed setting (100kHz only)
15- - pullup setting
16- - does not include the deadlock protection
12+ ## API
1713
14+ This is a pre-instantiated singleton library. It is not possible to use more
15+ than one instance per sketch or to change the instance name.
1816
19- ## Error codes
17+ The API syntax is very similar to the original C++ syntax. Some name
18+ mangeling was needed to distinguish the different variant of the ` read() `
19+ and ` write() ` method. Apart from this replacing the dots in the method names
20+ for underscores is all it needs.
2021
21- Return values for functions that use the timeOut feature will return at what
22- point in the transmission the timeout occurred .
22+ The pullup setting is missing because this function is supported by the STM8
23+ hardware .
2324
24- All possible return values:
2525
26- Errorcode | Meaning
27- ---: |---
28- 0 |Function executed with no errors
29- 1-7 |Timeout occurred, see above list
30- 8-0xFF|See datasheet for exact meaning
26+ Arduino syntax |sduino syntax
27+ -------------------- |---------------------
28+ ` I2C.begin() ` |` I2C_begin() `
29+ ` I2C.end() ` |` I2C_end() `
30+ ` I2C.timeOut(val) ` |` I2C_timeOut(val) `
31+ ` I2C.setSpeed(mode) ` |` I2C_setSpeed(mode) `
32+ ` I2C.pullup(active) ` |not implemented
33+ ` I2C.scan() ` |` I2C_scan() `
34+ ` n = I2C.available() ` |` n = I2C_available() `
35+ ` val = I2C.receive() ` |` val = I2C_receive() `
36+ ` I2C.write(addr, val) ` |` I2C_write(addr, val) `
37+ ` I2C.write(addr, reg, val) ` |` I2C_write_reg(addr, reg, val) `
38+ ` I2C.write(addr, reg, string) ` |` I2C_write_s(addr, reg, string) `
39+ ` I2C.write(addr, reg, *data, len) ` |` I2C_write_sn(addr, reg, *data, len) `
40+ ` I2C.read(addr, n) ` |` I2C_read(addr, n) `
41+ ` I2C.read(addr, reg, n) ` |` I2C_read_reg(addr, reg, n) `
42+ ` I2C.read(addr, n, *buf) ` |` I2C_readbuf(addr, n, *buf) `
43+ ` I2C.read(addr, reg, n, *buf) ` |` I2C_readbuf_reg(addr, reg, n, *buf) `
44+
45+
46+
47+ ### Error codes
3148
49+ All functions return an error code. Return values for functions that use the
50+ timeOut feature will return at what point in the transmission the timeout
51+ occurred.
3252
3353Looking at a full communication sequence between a master and slave
3454(transmit data and then readback data) there a total of 7 points in the
@@ -37,6 +57,7 @@ the returned value.
3757
3858Errorcode | Meaning: Waiting for...
3959---: |---
60+ 0 |Function executed with no errors
4061 1 |Waiting for successful completion of a Start bit
4162 2 |Waiting for ACK/NACK while addressing slave in transmit mode (MT)
4263 3 |Waiting for ACK/NACK while sending data to the slave
@@ -46,7 +67,15 @@ Errorcode | Meaning: Waiting for...
4667 7 |Waiting for successful completion of the Stop bit
4768
4869
49- ## AVR error codes
70+
71+ ### AVR error codes
72+
73+ For reference: The codes listed below where defined for the AVR, but they
74+ don't exist for the STM8 implementation. Combining the values of SR1 and SR2
75+ it would be possible to implement most of these conditions (apart from
76+ 0x20), but so far I haven't seen any program needing these values, so I
77+ didn't implement this.
78+
5079
5180Status Codes| for Master Transmitter Mode
5281--- |---
@@ -74,5 +103,24 @@ Status Codes| independed of mode
741030xF8 |No relevant state information available; TWINT = “0”
751040x00 |Bus error due to an illegal START or STOP condition
76105
77- Es braucht also SR1 und SR2
78- 0x20 ist nicht abzubilden.
106+
107+
108+
109+ ## inner workings
110+
111+ start(): Sends start bit, does not wait for SB flag.
112+ sendAddress()
113+
114+
115+ ## Further reading
116+
117+ Programming the I2C communication on the register level is quite complex for
118+ the STM8, especially in receive mode. The most detailed information on this
119+ topic is the
120+
121+ - application note AN3281 bundeled with
122+ - the related source code package [ STSW-STM8004] ( https://www.st.com/en/embedded-software/stsw-stm8004.html )
123+
124+ Downloading from the ST website requires a (free) registration. Somebody
125+ uploaded the full package to github:
126+ https://github.com/jiaohaitao/stsw-stm8004
0 commit comments