Go Down

Topic: [documentation] BUS I2C (Read 2933 times) previous topic - next topic

chabot380

Bonjour

De la doc sur le bus I2C ici : http://www.aurel32.net/elec/i2c.php

bonne lecture.
chabot380
ORDINAUSORE 2Ghz AMD64 QUI S'ALLUME EN 48 SECONDES AVEC UBUNTU 12.04
ARDUINO UNO / Shield Ethernet / RTC DS1307
Programmation Python et j'apprends le C
Technicien Télé Vidéo à la retraite.

jhdscript


nolimit60

Bonsoir chabot380,

J'ai trouvé dernièrement ce lien PDF:
http://artic.ac-besancon.fr/genie_electronique/telech/sonde/i2c.pdf


A+
Arduino 0023 et Python 3.2.3

fdufnews

#3
Jan 12, 2013, 07:15 pm Last Edit: Jan 28, 2013, 03:48 pm by fdufnews Reason: 1
Un petit programme qui scanne le bus à la recherche des éléments connectés.
Code: [Select]
// Wire Scanner
//
//
// Demonstrates the use of the Wire library
// Ping all valid adresses on the I²C bus
// and get the answer to see if there is a slave
// Print an 8 x 16 array with the results

// Created by fdufnews 2012 december 14th

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
 Wire.begin();         // join i2c bus (address optional for master)
 Serial.begin(9600);   // start serial for output
 Serial.println();     // Print a banner
 Serial.println();
 Serial.println("I2C slave scanner");
 Serial.println("   reserved adress");
 Serial.println(".  no slave detected");
 Serial.println("X  slave detected");
 Serial.println();
 Serial.println();
 int result;
 Serial.println("   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F");
 // Scan only valid addresses (8 to 0x7B)
 // 0-7 and 7C-7F are reserved ones
 unsigned char devices=0;                  // holds how many devices found
 for (unsigned char ad=0; ad<0x7C;ad++){
   if(ad%16==0){                           // If at start of a row
     Serial.print(ad>>4,HEX);              // Display high order bit address
     Serial.print(" ");
   }
   if (ad>7){                              // skip address from 0 to 7
     Wire.beginTransmission(ad);           // start transmission
     result = Wire.endTransmission();      // end transmission and store answer
     if (!result) devices++;               // add a device to the count if ACK
     Serial.print(" ");
     Serial.print(result==0?"X ":". ");    // If ACK there is a guy at this address
   }
   else{
     Serial.print("   ");                  // Sorry nobody here
   }
   if(ad%16==15) Serial.println();         // end of the row add a new line
 }
 Serial.println();
 Serial.println();
 Serial.println();
 Serial.print(devices, DEC);
 Serial.print(" device");
 Serial.print(devices>1?"s":"");
 Serial.println(" found on the bus");
}

void loop()
{

}

john_lenfr


Un petit programme qui scanne le bus à a recherche des éléments connectés.
Code: [Select]
// Wire Scanner
//
//
// Demonstrates the use of the Wire library
// Ping all valid adresses on the I²C bus
// and get the answer to see if there is a slave
// Print an 8 x 16 array with the results

// Created by fdufnews 2012 december 14th

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Wire.begin();         // join i2c bus (address optional for master)
  Serial.begin(9600);   // start serial for output
  Serial.println();     // Print a banner
  Serial.println();
  Serial.println("I2C slave scanner");
  Serial.println("   reserved adress");
  Serial.println(".  no slave detected");
  Serial.println("X  slave detected");
  Serial.println();
  Serial.println();
  int result;
  Serial.println("   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F");
  // Scan only valid addresses (8 to 0x7B)
  // 0-7 and 7C-7F are reserved ones
  unsigned char devices=0;                  // holds how many devices found
  for (unsigned char ad=0; ad<0x7C;ad++){
    if(ad%16==0){                           // If at start of a row
      Serial.print(ad>>4,HEX);              // Display high order bit address
      Serial.print(" ");
    }
    if (ad>7){                              // skip address from 0 to 7
      Wire.beginTransmission(ad);           // start transmission
      result = Wire.endTransmission();      // end transmission and store answer
      if (!result) devices++;               // add a device to the count if ACK
      Serial.print(" ");
      Serial.print(result==0?"X ":". ");    // If ACK there is a guy at this address
    }
    else{
      Serial.print("   ");                  // Sorry nobody here
    }
    if(ad%16==15) Serial.println();         // end of the row add a new line
  }
  Serial.println();
  Serial.println();
  Serial.println();
  Serial.print(devices, DEC);
  Serial.print(" device");
  Serial.print(devices>1?"s":"");
  Serial.println(" found on the bus");
}

void loop()
{

}



Nikel ce pti code, merci beaucoup ;)

jhdscript


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy