Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:netzer:i2c-master [2014/12/21 11:15] – Added framing feature. svesch | en:netzer:i2c-master [2025/06/11 20:42] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 8: | Line 8: | ||
===== NULL - The termination character ===== | ===== NULL - The termination character ===== | ||
| | ||
- | The character //0x00// in the TCP/ | + | The character //0x00// in the socket |
If Netzer sends a //0x00// either the bus is busy, a bus collission occurred or a slave does not respond on address or data bytes. | If Netzer sends a //0x00// either the bus is busy, a bus collission occurred or a slave does not respond on address or data bytes. | ||
In the latter cases the bus is freed with a stop condition automatically. | In the latter cases the bus is freed with a stop condition automatically. | ||
Line 21: | Line 21: | ||
===== The start condition and the slave address byte ===== | ===== The start condition and the slave address byte ===== | ||
- | A start condition is automatically announced on the bus, if Netzer gets the first character via the TCP/IP serial | + | A start condition is automatically announced on the bus, if Netzer gets the first character via socket. |
If an error occurs while announcing the start condition Netzer responds with a //0x00//. | If an error occurs while announcing the start condition Netzer responds with a //0x00//. | ||
I2C protocol defines the very first byte after the start condition as slave address. | I2C protocol defines the very first byte after the start condition as slave address. | ||
- | Netzer sends a //0x00// via TCP/ | + | Netzer sends a //0x00// via socket |
Also a stop condition is initiated by Netzer. | Also a stop condition is initiated by Netzer. | ||
- | After the successful (means acknowledged) transmission of the slave address Netzer sends //0xFF// via TCP/IP. | + | After the successful (means acknowledged) transmission of the slave address Netzer sends //0xFF// via socket. |
Line 43: | Line 43: | ||
If the R/W bit is **cleared** a transmission from master to slave is initiated. | If the R/W bit is **cleared** a transmission from master to slave is initiated. | ||
- | Each byte received by Netzer via the TCP/ | + | Each byte received by Netzer via the socket is directly sent to the slave (consider escaping!). |
- | In response Netzer sends via TCP/ | + | In response Netzer sends either ' |
In case of a negative acknowledge Netzer initiates a stop condition on the bus. | In case of a negative acknowledge Netzer initiates a stop condition on the bus. | ||
Line 50: | Line 50: | ||
If the R/W bit is **set** a transmission from slave to master is initiated (clock is generated by I2C master). | If the R/W bit is **set** a transmission from slave to master is initiated (clock is generated by I2C master). | ||
- | After the successful transmission of the slave address Netzer waits for further bytes on the TCP/ | + | After the successful transmission of the slave address Netzer waits for further bytes on the socket. |
- | On receiving a byte via TCP/ | + | On receiving a byte via socket |
In case the received byte is //0x00// the transmission is over and Netzer generates a stop condition on the bus. | In case the received byte is //0x00// the transmission is over and Netzer generates a stop condition on the bus. | ||
Any other value pulls the next byte from slave. | Any other value pulls the next byte from slave. | ||
Line 59: | Line 59: | ||
I2C supports repeated start. This symbol concatenates a stop and start condition while a I2C transmission is pending without freeing the bus inbetween. | I2C supports repeated start. This symbol concatenates a stop and start condition while a I2C transmission is pending without freeing the bus inbetween. | ||
- | The special character //s// (0x73) in TCP/ | + | The special character //s// (0x73) in socket |
Therefore //0x73// must be escaped during normal stream transmission to Netzer. | Therefore //0x73// must be escaped during normal stream transmission to Netzer. | ||
Exception to escaping //0x73// is the very first character (slave address) analog to the " | Exception to escaping //0x73// is the very first character (slave address) analog to the " | ||
- | <WRAP center round important 60%> | ||
Receiving //0x73// from Netzer has no special meaning but //0x73// and therefore will not be escaped! | Receiving //0x73// from Netzer has no special meaning but //0x73// and therefore will not be escaped! | ||
+ | <WRAP center round important 60%> | ||
+ | Attention: This feature has changed since version 1.6: //0x73// is escaped in both directions. | ||
</ | </ | ||
Line 75: | Line 76: | ||
Each action on the bus is considered like a socket frame terminated by //0x00//. | Each action on the bus is considered like a socket frame terminated by //0x00//. | ||
This rule is applied for both directions. | This rule is applied for both directions. | ||
+ | So each frame from host is replied by a socket frame. | ||
In case a frame is finished and no more frames wait for processing the socket is flushed. | In case a frame is finished and no more frames wait for processing the socket is flushed. | ||
- | This leads to a higher throughput especially on TCP/ | + | This leads to a higher throughput especially on network socket |
Line 98: | Line 100: | ||
+ | ===== Examples ===== | ||
+ | |||
+ | The following examples presume that there is a [[connection|connection]] to Netzer. | ||
+ | |||
+ | Take a look at the following picture for circuiting a I2C EEPROM IC as slave to Netzer. | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | |||
+ | ==== EEPROM slave address ==== | ||
+ | |||
+ | The EEPROM has the slave address 0x50. | ||
+ | Because the LSB is reserved for the R/W indicator the address is shifted left by one: //0xA0//. | ||
+ | |||
+ | |||
+ | ==== Writing to the EEPROM ==== | ||
+ | See the following byte sequence for writing a //0x55// to memory address 0 of the EEPROM: | ||
+ | < | ||
+ | Write per socket to Netzer: 0xA0 0x5C 0x00 0x55 0x00 | ||
+ | Answer from EEPROM received from Netzer: 0xFF 0xFF 0xFF 0x00 | ||
+ | </ | ||
+ | - //0xA0// is the slave address with the R/W bit cleared, means write access. | ||
+ | - Netzer returns //0xFF//, indicating the available slave. | ||
+ | - //0x5C 0x00// transfers the memory address 0 - of course must be backslashed (' | ||
+ | - Netzer returns //0xFF//, successful transfered memory address. | ||
+ | - //0x55// is the value written to EEPROM | ||
+ | - Netzer returns //0xFF//, successful transfered value. | ||
+ | - //0x00// stops the transmission - I2C bus is released. | ||
+ | - Socket sends //0x00// to the host - Frame termination | ||
+ | ==== Reading from EEPROM ==== | ||
+ | < | ||
+ | Write per TCP/IP to Netzer: 0xA0 0x5C 0x00 0x73 0xA1 0xFF 0x00 | ||
+ | Answer from EEPROM received per TCP/IP from Netzer: 0xFF 0xFF 0xFF 0xFF 0x55 0x78 0x00 | ||
+ | </ | ||
+ | - //0xA0// is the slave address with the R/W bit cleared, means write access. | ||
+ | - Netzer returns //0xFF//, indicating the available slave. | ||
+ | - //0x5C 0x00// transfers the memory address 0 - of course must be backslashed (' | ||
+ | - Netzer returns //0xFF//, successful transfered memory address. | ||
+ | - //0x73// initiates a repeated start on the bus. | ||
+ | - Netzer returns //0xFF//, successful repeated start. | ||
+ | - //0xA1// is the slave address with the R/W bit set, means read access. | ||
+ | - Netzer returns //0xFF//, indicating the available slave. | ||
+ | - //0xFF// from host: Pull me one byte from slave and acknowledge it. | ||
+ | - Netzer returns the value read from memory address 0: //0x55//. | ||
+ | - //0x00// from host: Pull me one more byte from slave and stop. | ||
+ | - Netzer returns the value read from memory address 1 (auto increment feature of the EEPROM): 0x78. | ||
+ | - Netzer automatically announces a stop condition after sending the byte. | ||
+ | - Socket sends //0x00// to the host - Frame termination | ||