RetroBSD

2.11BSD operating system for microcontrollers
It is currently Wed Jul 17, 2019 2:50 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: I2C scanner
PostPosted: Fri Dec 13, 2013 2:53 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
This scans for available I2C devices:
i2cscan.c:
Code:
// I2C BUS DEVICE SCAN
// Prints out the available I2C device's addresses
// Compile under uecide
// Pito 12/2012

#include "i2c.h"

int main ()
{
   unsigned i, ff = 0;
   // init the pins driver !!
   if (pinsinit() < 0) return 66;
   // init i2c driver
   I2CInit();

   printf("I2C dev found, adr(r/w): ");

   for (i=0; i<255; i=i+2){
      I2CStart();
      if (I2CSend(i) == ACK){
         printf("%02X(%02X/%02X)  ", i>>1, i+1, i);
         ++ff;
      }
      I2CStop();
   }

   if (ff == 0) printf("None\n");
   else printf("\n");

   pinsclose();
   return 0;
}


An example - RTC8563 and 10DOF module (GY-80, accel, gyro, magnet, baro):
Code:
# ./i2cscan
I2C dev found, adr(r/w): 1E(3D/3C)  51(A3/A2)  53(A7/A6)  69(D3/D2)  77(EF/EE)
#


and built into rc:
Code:
..
Size: 2572 kbytes
Inodes: 160
I2C dev found, adr(r/w): 1E(3D/3C)  51(A3/A2)  53(A7/A6)  69(D3/D2)  77(EF/EE)
RTC:  1312131644.26
Fri Dec 13 16:44:26 PST 2013
Starting daemons: update cron
..

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission