I try to get MySensors working on an ATtiny 84 with RFM69CW module. I use the Tiny TX 3 Sensor board. I know, because of little memory, I can use this for reel simple nodes, at the best.
First I do some changes to get MYSensors to compile with the ATTiny core.
I have to disable serialEventRun in MySensors main (MyMainAVR.cpp) because there is no serial interface on ATtiny:
int main(void)
{
init();
#if defined(USBCON)
USBDevice.attach();
#endif
_begin(); // Startup MySensors library
for(;;) {
_process(); // Process incoming data
if (loop) {
loop(); // Call sketch loop
}
// MCU like ATtiny don't support serial
#if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3)
if (serialEventRun) {
serialEventRun();
}
#endif
}
return 0;
}
I also have to change clearPendingInterrupt (MyHWAVR.cpp) because ATtiny 84 only have on interrupt and use an other register:
void clearPendingInterrupt(const uint8_t interrupt)
{
#ifdef ATTINY_CORE
// Flag for INT0 / ATtiny84 is on Bit 6 in GIFR
if (interrupt == 0)
GIFR = _BV(interrupt + 6);
#else
EIFR = _BV(interrupt);
#endif
}
I also have to change hwUniqueID (MyHWAVR.cpp). I know this code don't really return a unique ID. At the moment I have no idea how to do this for ATtiny. But I think also that souldn't prevent MySensors from working.
bool hwUniqueID(unique_id_t *uniqueID)
{
// padding
(void)memset(uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t));
#ifndef ATTINY_CORE
// no unique ID for non-PB AVR, use HW specifics for diversification
*((uint8_t *)uniqueID) = boot_signature_byte_get(0x00);
*((uint8_t *)uniqueID + 1) = boot_signature_byte_get(0x02);
*((uint8_t *)uniqueID + 2) = boot_signature_byte_get(0x04);
*((uint8_t *)uniqueID + 3) = boot_signature_byte_get(0x01); //OSCCAL
#endif
#if defined(__AVR_ATmega328PB__)
// ATMEGA328PB specifics, has unique ID
for(uint8_t idx = 0; idx < 10; idx++) {
*((uint8_t *)uniqueID + 4 + idx) = boot_signature_byte_get(0xE + idx);
}
return true; // unique ID returned
#else
return false; // no unique ID returned
#endif
}
With this little changes, which I think aren't completely wrong, MySensors compile for ATtiny. At least after this changes it compiles for the Attiny 84 on TinyTX3 and for my Arduino Nano which I also use for testing.
I got also message sent to my gateway from the ATiny. But it seems, it never receives the incoming message because I get this log:
TSF:MSG:READ,5-5-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
TSF:MSG:BC
TSF:MSG:FPAR REQ,ID=5
TSF:PNG:SEND,TO=0
TSF:CKU:OK
TSF:MSG:GWL OK
TSF:MSG:SEND,0-0-5-5,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
TSF:MSG:READ,5-5-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
TSF:MSG:BC
TSF:MSG:FPAR REQ,ID=5
TSF:CKU:OK,FCTRL
TSF:MSG:GWL OK
TSF:MSG:SEND,0-0-5-5,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
TSF:MSG:READ,5-5-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
TSF:MSG:BC
TSF:MSG:FPAR REQ,ID=5
TSF:CKU:OK,FCTRL
TSF:MSG:GWL OK
TSF:MSG:SEND,0-0-5-5,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
TSF:MSG:READ,5-5-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
TSF:MSG:BC
TSF:MSG:FPAR REQ,ID=5
TSF:CKU:OK,FCTRL
TSF:MSG:GWL OK
TSF:MSG:SEND,0-0-5-5,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
...
An endless I_FIND_PARENT_REQUEST / I_FIND_PARENT_RESPONSE sequence The same program on Arduino Nano works.
My first idea was, that the interrupt on ATtiny don't work (because I changes the code for clearPendingInterrupt how you can see above ). But I set an output pin to debug (because I have no serial on ATtiny) in the interrupt routine and it seems that at least it is called.
By check the output pins I also see the (Arduino) pin 8 and 9 is set to high. I don't know why. I don't set thess in my program but I also don't see at the moment that they are set in the MySensors code.
Does anyone have an idea why pin 8 and 9 is high? Or why incoming messages aren't processed?