[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
es:howtos:hardware:arm:interfacing_i2c_devices [2019/07/16 22:51 (UTC)] – [Sources] rramp | es:howtos:hardware:arm:interfacing_i2c_devices [2019/07/31 01:42 (UTC)] (actual) – Traducción completa. Comentarios y sugerencias son bienvenidas. rramp | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
- | <note important> | ||
====== Conectando dispositivos I2C a tu sistema ====== | ====== Conectando dispositivos I2C a tu sistema ====== | ||
- | Inter-Integrated Circuit | + | Circuito |
+ | y de uso común en muchos dispositivos electrónicos modernos, incluyendo | ||
+ | I²C usa solo dos lineas bidireccionales open-drain, Serial Data Line (SDA) y Serial Clock Line(SCL), llevados al nivel lógico 1 por resistencias de pullup. | ||
+ | Típicamente son empleadas tensiones de +5 Volt o +3,3 Volt aunque sistemas con otras tensiones son permitidas. Esto tiene una implicación interesante: | ||
+ | Para más información, | ||
- | I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled to logic level 1 by pullup resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted and are often encountered. This has an interesting implication: | ||
- | ====== | + | ====== |
- | Most modern | + | La mayoría de las computadoras personales (PC) modernas tienen componentes internos que comunican información |
- | ====== | + | ====== |
- | Before you start you might want to make sure that the OS has all that's required to manage the I2C bus you will be using. | + | |
- | The first thing to do is make sure you have the correct kernel driver for whatever physical layer implementation is on your system. You will have to research on the datasheets of your system' | + | |
- | Once you have the drivers right you might like to have a user-space tool to help you detect buses, present devices and communicate with the I2C devices each bus. I use i2ctools for this but it's not packaged amongst the Slackware packages and I was unable to find ant third party providing an ARM Slackware package so I downloaded the sources and compiled it for myself. Sources can be gotten from here: [[ http://www.lm-sensors.org/ | + | Antes de empezar, es posible que desee asegurarse de que el sistema operativo tiene todo lo necesario para gestionar el bus I2C que va a utilizar. |
+ | Lo primero que hay que hacer es asegurarse de que tiene el controlador de kernel correcto para cualquier implementación de capa física en su sistema. | ||
+ | Tendrás que investigar en las hojas de datos del hardware de tu sistema... mi Pi tiene bcm2708 así que en mi caso se trataba de cargar el módulo bcm2708_i2c. También puede ser necesario cargar el módulo i2c-dev dependiendo de su configuración. | ||
+ | Una vez que tenga los controladores correctos, es posible que desee disponer de una herramienta de espacio de usuario que le ayude a detectar buses, presentar dispositivos y comunicarse con los dispositivos I2C de cada bus. | ||
+ | Utilizo i2ctools para esto pero no está empaquetado entre los paquetes de Slackware y no pude encontrar un tercero que ofreciera un paquete de ARM Slackware, así que descargué las fuentes y las compilé para mí mismo. | ||
+ | Las fuentes se pueden obtener desde aquí: [[ http:// | ||
- | ====== | + | ====== |
- | Provided you've sorted out the voltage level issues (see the " | + | |
- | ===== Detecting Connected Devices ===== | + | Siempre que haya resuelto los problemas de nivel de tensión (consulte el capítulo " |
- | There are probably many ways to determine what's connected to an I2C bus, I chose to use stuff out of the [[http://www.lm-sensors.org/ | + | El bus es multimaestro, lo que significa que puedes tener muchos dispositivos (hasta 101) en el mismo bus, así que todo lo que tienes que hacer es hacer 4 conexiones: Potencia, tierra, SDA y SCL. |
+ | Si es el primer dispositivo que conecta en el bus, puede ser necesario instalar resistencias de pullups entre Power-SDA y Power-SCL. Es tan simple como eso y si el sistema está listo con los controladores apropiados y las utilidades del país del usuario, usted está listo para acceder al dispositivo recién conectado. | ||
- | First thing you want to know is what I2C busses are present on your system as there may be more then one and looking in the wrong bus may be frustrating: | + | ===== Detectando dispositivos conectados ===== |
+ | |||
+ | Hay probablemente muchas formas para determinar que está conectado a un bus I2C. Elegí usar cosas del proyecto [[http:// | ||
+ | |||
+ | Lo primero que debe saber es qué buses I2C están presentes en su sistema, ya que puede haber más de uno y mirar en el bus equivocado puede ser frustrante: | ||
root@pi:~# i2cdetect | root@pi:~# i2cdetect | ||
Línea 28: | Línea 37: | ||
root@pi:~# | root@pi:~# | ||
- | If you're not sure which bus you connected your stuff on you might want to do this on on all the busses: | + | Si no estás seguro de en qué bus conectaste tus cosas, es posible que quieras hacer esto en todos los buses: |
root@pi:~# i2cdetect -y 1 | root@pi:~# i2cdetect -y 1 | ||
Línea 42: | Línea 51: | ||
root@pi:~# | root@pi:~# | ||
- | ===== Communicating With An I2C Device | + | ===== Comunicación con un dispositivo |
- | Communication with I2C devices id done by reading and writing to it's registers. Each device has it's own register list and is something you need to look for in the device' | + | La comunicación con dispositivos |
- | Registers can be set by using i2cset | + | Cada dispositivo tiene su propia lista de registros y es algo que debe buscar en la hoja de datos del dispositivo. |
+ | Algunos dispositivos incluso necesitan que se realice una calibración preliminar antes de que pueda leer cualquier dato sensible | ||
+ | Los registros se pueden establecer utilizando | ||
+ | |||
+ | Incluso una vez que sepa si su dispositivo necesita calibración y los registros involucrados, | ||
- | Even once you know if your device needs calibration and the registers involved, the content of the registers may not be in a convenient format for ready use. There are generally various scripts in perl or python that address calibrating and managing data from specific | + | En este punto es imposible mostrar más información sobre la comunicación I1C sin entrar en detalles sobre un dispositivo específico, así que voy a elegir uno de los dispositivos de mi pcb IMU. Al detectar previamente en mi PI encontré 4 dispositivos con las direcciones hexadecimales fluyentes: 1e,40,69 y 77. |
+ | Generalmente cada dispositivo | ||
+ | No que nosotros necesitamos es la tabla del ITG3200: | ||
- | At this point it's impossible to show any further info about I1C communication without going into some detail about a specific device so I'll pick one ot the devices on my IMU pcb. While detecting previously on my PI I found 4 devices with the flowing hex addresses: 1e,40,69 and 77. | ||
- | Generally each I2C device has a range of addresses than can set. We shall concentrate on the device with 0x69 address. By doing some cross reference search on the IMU pcb datasheet and on the single datasheets of each device present on my IMU it's revealed that 0x69 should be the address of the ITG3200 (gyro + temp sensor) and indeed the ITG3200 datasheet asserts that it can have either 0x68 or 0x69 address selectable by logic level on pin 9. No what we need is the ITG3200 register chart: | ||
Addr Addr | Addr Addr | ||
Línea 68: | Línea 81: | ||
| | ||
- | I chose the ITG3200 | + | Elegí el ITG3200 |
root@pi:~# i2cdump | root@pi:~# i2cdump | ||
Línea 75: | Línea 88: | ||
root@pi:~# | root@pi:~# | ||
- | The above example dumps registers | + | El ejemplo de arriba muestra los registros de volcado |
root@pi:~# i2cget -y 1 0x69 0x1b b | root@pi:~# i2cget -y 1 0x69 0x1b b | ||
Línea 82: | Línea 95: | ||
0x90 | 0x90 | ||
root@pi:~# | root@pi:~# | ||
- | + | | |
- | So we got c090 as our temperature reading. According to the datasheet this value is a 2's compliment of the temperature. So let's try and figure out what that would be: c090 written in binary is 1100000010010000, | + | así que tenemos el registro |
16528 - 32768 = -16240 | 16528 - 32768 = -16240 | ||
- | I was unable to find in the datasheet what units this reading is in but they did mention that there was an average offset of 13200. | + | |
+ | No pude encontrar en la hoja de datos en qué unidades se encuentra esta lectura, pero sí mencionaron que había una compensación promedio de 13200. | ||
35 + ((raw value + 13200) / 280)) | 35 + ((raw value + 13200) / 280)) | ||
35 + ((13200 - 16240)/280) = 24.14 | 35 + ((13200 - 16240)/280) = 24.14 | ||
- | Considering that my current ambient temperature is about 20 Celcius | + | Considerando que mi temperatura ambiente actual es cerca de 20 grados |
- | If you want a script | + | Si quieres un script |
#!/bin/bash | #!/bin/bash | ||
Línea 135: | Línea 149: | ||
echo " | echo " | ||
- | The above script | + | El script |
- | A bash script | + | Un script |
+ | La documentación del núcleo de Linux para i2c me pareció una referencia útil (<kernel source tree>/ | ||
- | I hate showing my poor C programming capabilities but here's some code that uses i2c-dev | + | Odio mostrar mis pobres capacidades de programación en C, pero aquí hay un código que usa i2c-dev |
#include < | #include < | ||
Línea 257: | Línea 272: | ||
- | ====== | + | ====== |
- | You may end up with heterogeneous voltage level devices and if you have many devices the correct way to work around this problem is by using bidirectional | + | |
- | This is how I connected my 5v IMU pcb to a 3.3v I2C bus on my RaspberryPI: | + | Usted puede terminar con dispositivos de nivel de voltaje heterogéneo y si tiene muchos dispositivos, |
+ | Así es como conecté mi PCB IMU de 5V a un bus I2C de 3.3V en mi Raspberry | ||
+ | Tomé como supuesto que 4.4 V (5V con un diodo en serie 1N4148) seguiría siendo una tensión de alimentación tolerable para toda la pcb IMU, lo que probablemente permitiría a todos los dispositivos I2C de la pcb IMU reconocer un mínimo de 3.08 V. (4.4 * 0.7) como la tensión de nivel lógico 1 más baja y fiable, lo que le permitiría interoperar con los niveles lógicos de 3.3V de la Raspberry PI. | ||
+ | No pude encontrar si la Raspberry Pi tiene Resistencias de pullups internas en el bus I2C o si tienen que ser colocados externamente, | ||
====== Fuentes ====== | ====== Fuentes ====== | ||
<!-- If you are copying information from another source, then specify that source --> | <!-- If you are copying information from another source, then specify that source --> |