Skip to content

Instantly share code, notes, and snippets.

@systmkor
Created July 15, 2014 23:04
Show Gist options
  • Save systmkor/1003b94a945b7ec5857e to your computer and use it in GitHub Desktop.
Save systmkor/1003b94a945b7ec5857e to your computer and use it in GitHub Desktop.
i2c between two MSP403s
//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();
}
}
//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