Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1993 | - | 1 | /*HMC5883LRegisterScanner.pde |
2 | **A sketch that attempts to read every register from a slave device |
||
3 | **Written by Wayne Truchsess http://dsscircuits.com |
||
4 | */ |
||
5 | |||
6 | #include "Wire.h" |
||
7 | #define I2C 0x77 |
||
8 | |||
9 | byte x; |
||
10 | |||
11 | void setup() { |
||
12 | Wire.begin(); |
||
13 | Serial.begin(9600); |
||
14 | delay(1000); |
||
15 | } |
||
16 | |||
17 | void loop() { |
||
18 | readRegisters(); |
||
19 | } |
||
20 | |||
21 | void readRegisters() { |
||
22 | for(int l = 0x00; l < 256; l++){ |
||
23 | Wire.beginTransmission(I2C); |
||
24 | Wire.send(l); |
||
25 | Wire.endTransmission(); |
||
26 | //delay(100); |
||
27 | Wire.beginTransmission(I2C); |
||
28 | Wire.requestFrom(I2C,1); |
||
29 | x = Wire.receive(); |
||
30 | Serial.print("Register Address "); |
||
31 | Serial.print(l,DEC); |
||
32 | Serial.print("_"); |
||
33 | Serial.print(l,HEX); |
||
34 | Serial.print(" = "); |
||
35 | Serial.print(x,BIN); |
||
36 | Serial.print(" = "); |
||
37 | Serial.print(x,DEC); |
||
38 | Serial.println(" "); |
||
39 | Wire.endTransmission(); |
||
40 | } |
||
41 | } |