Hi @peekay123,
I now know the problem was not the pin names but it looks like I cannot use Wire (I2C) properly on P1. I am using the exact same HW setup as Photon and Core (both worked fine). I can initialize I2C with wire.begin() but had problem setting speed (P1 flashed red after OTAFU).
When I use the following simplified code to write to test registers in a slave device, I was able to flash P1, though it would reset itself right after communicating with the cloud (flashing cyan). I am not sure what the problem is. My code is below:
#include “application.h”
const int button1 = D5;
const int button2 = D6;
int button1State;
int button2State;
int lastButton1State = LOW;
int lastButton2State = LOW;
long lastDebounceTime = 0;
long debounceDelay = 40;
// Initialize I2C Registers
#define DEVICE_ADDR 1
#define NUM_BYTES_READ 5
#define NUM_BYTES_WRITE 5
byte i2cSendBuffer[NUM_BYTES_WRITE];
void setup() {
// Start I2C and write to test registers in slave device
I2Cs_InitControl();
i2cSendBuffer[0] = 0x01;
i2cSendBuffer[1] = 0x00;
i2cSendBuffer[2] = 0x11;
i2cSendBuffer[3] = 0x00;
i2cSendBuffer[4] = 0x22;
I2Cs_Write(DEVICE_ADDR, 0, i2cSendBuffer, NUM_BYTES_WRITE);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
}
void loop() {
int reading1 = digitalRead(button1);
if (reading1 != lastButton1State) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading1 != button1State) {
button1State = reading1;
if (button1State == HIGH) {
i2cSendBuffer[0] = 0x00;
I2Cs_Write(DEVICE_ADDR, 0, i2cSendBuffer, 1);
}
}
}
lastButton1State = reading1;
int reading2 = digitalRead(button2);
if (reading2 != lastButton2State) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading2 != button2State) {
button2State = reading2;
if (button2State == HIGH) {
i2cSendBuffer[0] = 0x01;
I2Cs_Write(DEVICE_ADDR, 0, i2cSendBuffer, 1);
}
}
}
lastButton2State = reading2;
}
void I2Cs_InitControl(void)
{
//Wire.setSpeed(400000);
Wire.begin();
}
void I2Cs_Write(byte slaveAddr, byte subAddrValue, byte* dataArray, byte length)
{
Wire.beginTransmission(slaveAddr);
Wire.write(subAddrValue);
Wire.write(dataArray, length);
Wire.endTransmission();
}