Created
July 15, 2014 23:04
-
-
Save systmkor/1003b94a945b7ec5857e to your computer and use it in GitHub Desktop.
i2c between two MSP403s
This file contains hidden or 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
//i2c Slave Code(LAUNCHPAD) | |
#include <Wire.h> | |
void setup() | |
{ | |
Wire.begin(8); //join i2c bus with addres 8 | |
Wire.onReceive(receiveEvent); | |
pinMode(6,OUTPUT); | |
pinMode(RED_LED, OUTPUT); | |
digitalWrite(RED_LED, LOW); | |
blink(); | |
Serial.begin(9600); | |
Serial.println("Starting i2c Slave"); | |
} | |
void loop() { | |
delay(100); | |
} | |
void blink() { | |
digitalWrite(RED_LED, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(100); // wait for a second | |
digitalWrite(RED_LED, LOW); // turn the LED off by making the voltage LOW | |
delay(100); | |
} | |
void receiveEvent(int howMany) { | |
while(Wire.available()) { | |
char c = Wire.read(); | |
blink(); | |
} | |
} |
This file contains hidden or 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
//i2c Master Code(MEGA) | |
#include <Wire.h> | |
void setup() | |
{ | |
Wire.begin(); | |
delay(200); | |
} | |
void loop() | |
{ | |
Wire.beginTransmission(8); | |
Wire.write('H'); | |
Wire.endTransmission(); | |
delay(300); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment