Ligne 157 : |
Ligne 157 : |
| === Opérations standard du bus === | | === Opérations standard du bus === |
| {{traduction}} | | {{traduction}} |
− | Travail à poursuivre à [https://docs.micropython.org/en/latest/library/machine.I2C.html#standard-bus-operations partir d'ici]
| |
| | | |
| + | The following methods implement the standard I2C master read and write operations that target a given slave device. |
| | | |
− | ==== i2c.mem_write(...) ==== | + | ==== I2C.readfrom(...) ==== |
− | i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8) | + | i2c.readfrom(addr, nbytes, stop=True) |
| | | |
− | Ecrit dans la mémoire d'un périphérique I2C.
| + | Read {{fname|nbytes}} from the slave specified by {{fname|addr}}. If {{fname|stop}} is {{fname|True}} then a STOP condition is generated at the end of the transfer. |
| + | |
| + | Returns a {{fname|bytes}} object with the data read. |
| | | |
− | * '''data''' est entier ou un ''buffer'' contenant les données à envoyer au périphérique I2C.
| |
| * '''addr''' est l'adresse du périphérique I2C. | | * '''addr''' est l'adresse du périphérique I2C. |
− | * '''memaddr''' est la position mémoire (adresse mémoire) dans le périphérique I2C. | + | * '''nbytes''' xxx . |
− | * '''timeout''' est le temps d'attente max (millisecondes) pour démarrer l'opération d'écriture. | + | * '''stop''' xxx . |
− | * '''addr_size''' permet de sélectionner la taille de {{fname|memaddr}}: 8 ou 16 bits
| + | |
| + | ==== I2C.readfrom_into(...) ==== |
| + | i2c.readfrom_into(addr, buf, stop=True) |
| + | |
| + | Read into {{fname|buf}} from the slave specified by {{fname|addr}}. The number of bytes read will be the length of buf. |
| + | |
| + | If {{fname|stop}} is {{fname|True}} then a STOP condition is generated at the end of the transfer. |
| | | |
− | Retourne {{fname|None}}.
| + | The method returns {{fname|None}}. |
| | | |
− | Uniquement valable en mode ''master''.
| + | * '''addr''' l'adresse depuis laquelle les données seront réceptionnées. |
| + | * '''buf''' |
| + | * '''stop'''& xxx . |
| | | |
− | ==== i2c.recv(...) ==== | + | ==== I2C.writeto(...) ==== |
− | i2c.recv(recv, addr=0x00, timeout=5000) | + | i2c.writeto(addr, buf, stop=True) |
| | | |
− | Recevoir des données sur le bus:
| + | Write the bytes from {{fname|buf}} (objet de type {{fname|bytes}} to the slave specified by {{fname|addr}}. |
− | * '''recv''' peut être un entier représentant le nombre d'octets/bytes à recevoir --OU-- un ''buffer'' mutable (''modifiable'') qui sera remplis avec les octets reçus.
| |
− | * '''addr''' l'adresse depuis laquelle les données seront reçues (uniquement valable en mode ''master'')
| |
− | * '''timeout''' le temps d'attente max pour recevoir les données. ''TimeOut'' s'exprimant en millisecondes.
| |
| | | |
− | Valeur retournée: si {{fname|recv}} est un entier alors la fonction retourne un nouveau ''buffer'' (mémoire tampon) avec les octets/bytes reçu --sinon-- ce sera la même buffer que celui passé dans le paramètre {{fname|recv}}.
| + | If a '''NACK''' is received following the write of a byte from buf then the remaining bytes are not sent. |
| | | |
− | ==== i2c.scan() ==== | + | If {{fname|stop}} is {{fname|True}} then a STOP condition is generated at the end of the transfer, even if a '''NACK''' is received. |
− | Scanne toutes les adresses du Bus I2C de 0x01 à 0x7f et retourne la liste des adresses offrant une réponse.
| + | |
| + | The function returns the number of '''ACK'''s that were received. |
| + | |
| + | * '''addr''' l'adresse vers laquelle les données seront envoyées. |
| + | * '''buf''' |
| + | * '''stop''' xxx . |
| + | |
| + | === Opérations mémoire === |
| + | Some I2C devices act as a memory device (or set of registers) that can be read from and written to. In this case there are two addresses associated with an I2C transaction: the slave address and the memory address. The following methods are convenience functions to communicate with such devices. |
| + | |
| + | ==== I2C.readfrom_mem(...) ==== |
| + | I2C.readfrom_mem(addr, memaddr, nbytes, *, addrsize=8) |
| + | |
| + | Read {{fname|nbytes}} from the slave specified by {{fname|addr}} starting from the memory address specified by {{fname|memaddr}}. |
| + | |
| + | The argument {{fname|addrsize}} specifies the address size in bits. |
| + | |
| + | Returns a {{fname|bytes}} object with the data read. |
| + | |
| + | ==== I2C.readfrom_mem_into(...) ==== |
| + | i2c.readfrom_mem_into(addr, memaddr, buf, *, addrsize=8) |
| + | |
| + | Read into {{fname|buf}} from the slave specified by {{fname|addr}} starting from the memory address specified by {{fname|memaddr}}. |
| + | |
| + | The number of bytes read is the length of {{fname|buf}}. |
| + | |
| + | The argument {{fname|addrsize}} specifies the address size in bits (on ESP8266 this argument is not recognised and the address size is always 8 bits). |
| + | |
| + | The method returns {{fname|None}}. |
| + | |
| + | ==== I2C.writeto_mem(...) ==== |
| + | i2c.writeto_mem(addr, memaddr, buf, *, addrsize=8) |
| + | |
| + | Write {{fname|buf}} to the slave specified by {{fname|addr}} starting from the memory address specified by {{fname|memaddr}}. |
| + | |
| + | The argument {{fname|addrsize}} specifies the address size in bits (on ESP8266 this argument is not recognised and the address size is always 8 bits). |
| | | |
− | Cette instruction est uniquement utilisable en mode ''master''.
| + | The method returns {{fname|None}}. |
| | | |
− | ==== i2c.send(...) ==== | + | === Autres opérations === |
− | i2c.send(send, addr=0x00, timeout=5000)
| + | ==== i2c.scan() ==== |
| + | Scanne toutes les adresses du Bus I2C de 0x01 à 0x7f et retourne une liste Python des adresses offrant une réponse. |
| | | |
− | Envoi des données sur le bus:
| + | A noter que certains composant (comme le {{pl|932|AM2315}}) n'offrent pas de réponse et ne sont donc pas détectable par cette méthode. |
− | * '''send''' est la donnée à envoyer (un entier/integer ou un objet ''buffer'')
| |
− | * '''addr''' est l'adresse du destinataire (uniquement nécessaire en mode ''master'')
| |
− | * '''timeout''' est le temps d'attente max (''timeout'') pour l'envoi des données. Temps en millisecondes
| |
| | | |
− | Valeur retournée: {{fname|None}}.
| + | Hormis ce détail, il s'agit d'une méthode fiable car la plupart des composants répondent. |
| | | |
| === Constantes === | | === Constantes === |