rambo / TinyWire

My modifications to TinyWire Arduino libs
284 stars 121 forks source link

Only getting 255 as result #16

Closed JRTax closed 8 years ago

JRTax commented 8 years ago

Hello,

I'm already a day or 2 into programming a attiny85 with the TinyWire library. And I'm getting constantly the same result, which is 255.

I'm using the attiny85 as slave, for the decoding of incomming IR signals.

The code of the slave is:

include "IRLremote.h"

include "PinChangeInterrupt.h"

include "TinyWireS.h"

define IRL_BLOCKING true

define pinIR 3 // Attiny pin 2

define ledPin 4 // Attiny pin 3

define I2C_Slave_Addr 0x4 // I2C slave address (38)

uint8_t IRProtocol = 0; uint16_t IRAddress = 0; uint32_t IRCommand = 0;

byte x = 1; byte y = 2;

void setup() { attachPCINT(digitalPinToPCINT(pinIR), IRLinterrupt, CHANGE); TinyWireS.begin(I2C_Slave_Addr); TinyWireS.onReceive(receiveEvent); TinyWireS.onRequest(requestEvent);

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);

}

void loop() { TinyWireS_stop_check(); }

void requestEvent() { uint8_t oldSREG = SREG; cli(); if (IRProtocol) { switch(IRCommand) { case 0x1F: TinyWireS.send(x); break; case 0xF: TinyWireS.send(y); break; } IRProtocol = 0; } SREG = oldSREG; }

void IREvent(uint8_t protocol, uint16_t address, uint32_t command) { if (IRL_BLOCKING && !IRProtocol) { IRProtocol = protocol; IRAddress = address; IRCommand = command; } }

The code of the master is:

include

byte value;

void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output Serial.println("Start program"); }

void loop() { Wire.requestFrom(4, 1); if (Wire.available()) { value = Wire.read(); }

Serial.println(value); 
delay(500);

}

What is the problem? I'm already 2 days looking in the program, and trying but I cant find the solution.

You can find the IRLremote library here: https://github.com/NicoHood/IRLremote And the PinChangeInterrupt here: https://github.com/NicoHood/PinChangeInterrupt

rambo commented 8 years ago

Duplicate of #15