Last active
August 29, 2015 14:02
-
-
Save murilopontes/0ba6804a51ca00cb7afb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Energia 0101E0012 (03/18/2014) | |
// http://energia.nu/download/ | |
#include <Wire.h> | |
//printf | |
#include <stdarg.h> | |
void p(char *fmt, ... ){ | |
char buf[128]; | |
va_list args; | |
va_start (args, fmt ); | |
vsnprintf(buf, 128, fmt, args); | |
va_end (args); | |
Serial.print(buf); | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
Wire.begin(); | |
} | |
void loop() | |
{ | |
byte addr=0; | |
byte value = 0; | |
p("i2c scanner start\r\n"); | |
for(addr=0;addr<128;addr++){ | |
Wire.beginTransmission(addr); | |
Wire.write(0x0); /////////////////////// energia i2c issue | |
uint8_t error=Wire.endTransmission(); | |
switch(error){ | |
case 0: p("\33[1;32m%02x\33[m|",addr); break; | |
case 4: p("\33[1;33mEE\33[m|"); break; | |
default: p("\33[1;31mXX\33[m|"); break; | |
} | |
if((addr+1)%16==0) p("\r\n"); | |
} | |
p("i2c scanner end\r\n"); | |
for(value=1;value<7;value++){ | |
for(addr=1;addr<4;addr++){ | |
///////////////////////////////////// testing write | |
Wire.beginTransmission(addr); | |
Wire.write(value); | |
uint8_t error=Wire.endTransmission(); | |
p("master i2c write addr=%02x error=%02x value=%02x\r\n",addr,error,value); | |
///////////////////////////////////// testing request | |
error=Wire.requestFrom(addr, 6); | |
p("master i2c request addr=%02x error=%02x response=[",addr,error); | |
while(Wire.available()){ | |
uint8_t r = Wire.read(); | |
p("%02x",r); | |
} | |
p("]\r\n"); | |
} | |
delay(500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment