MicroCore - An optimized and efficient Arduino core for ATtiny13

OK here is the main part of the code, i added the complete code and the receiver code below

This is a minimal sensor transmitter with attiny13 and nrf24l01 that can last 1 year+ on a single 2032 battery, it takes adc readings on a thermistor and a voltage divider.

#include "API.H"

#include <avr/sleep.h>
#include <stdio.h>
#include <string.h>

ISR(WDT_vect) {NOP;}

#define SPI_PORT PORTB
#define CE 2
#define CSN 5
#define SPI_SCK 1
#define SPI_MOSI 0

#define cbi(x,y)    x&= ~(1<<y)
#define sbi(x,y)    x|= (1<<y)


#define SPI_DDR (*((&SPI_PORT) -1))
#define SPI_PIN (*((&SPI_PORT) -2))


#define adc_int 2
#define adc_stand 3
byte adc_internalRead=0;

struct dataStruct{
  int adc_therm;
  int adc_volt;
  unsigned long counter;
  byte id; 
}myData;

//***************************************************
#define TX_ADR_WIDTH    3   // 5 unsigned chars TX(RX) address width
#define TX_PLOAD_WIDTH     sizeof(myData)   // 32 unsigned chars TX payload

byte TX_ADDRESS[TX_ADR_WIDTH]  = 
{
  0xb1,0x43,0x20
}; // Define a static TX address


unsigned char tx_buf[TX_PLOAD_WIDTH] = {0};


int main(void){
init();
{
myData.id='U';
delay(1000);
   WDTCR |= (1<<WDP3);

   WDTCR |= (1<<WDTIE);

   sei(); // Enable global interrupts 

   // Use the Power Down sleep mode
   set_sleep_mode(SLEEP_MODE_PWR_DOWN);

SPI_DDR |= ((1<<SPI_SCK) | (1<<SPI_MOSI)| (1<<CE)| (1<<CSN));

  sbi (SPI_PORT, CSN);                          // Initialize IO port

   TX_Mode();                      // set TX mode

}




while(1) {

 ADCSRA |= (1<<ADEN);
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e); //pwr upp
delayMicroseconds(2000);
SPI_RW_Reg(FLUSH_TX,0);
delayMicroseconds(100);

  sbi (SPI_PORT, CE); 
      
  if(adc_internalRead==1)
  {
  myData.adc_volt = analogRead(adc_int);
  analogReference(DEFAULT);
  adc_internalRead=0;
  
  }
  else
  {
  myData.adc_therm = analogRead(adc_stand);
  analogReference(INTERNAL);
  adc_internalRead=1;
  
  }

  cbi (SPI_PORT, CE); 
  
  memcpy(tx_buf, &myData, sizeof(myData));
    
  SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);
  SPI_RW_Reg(WRITE_REG+STATUS,0xff); 
 
sbi (SPI_PORT, CE);
delayMicroseconds(30);
cbi (SPI_PORT, CE);
delayMicroseconds(650);


SPI_RW_Reg(WRITE_REG + CONFIG, 0x00);   //pwr down
ADCSRA &= ~(1<<ADEN);
myData.counter++;
sleep_mode();
   
}
}

Here is a print screen of the memcpy problem, the first readings are with microcore the other with Smeezekitty's core13

Any tips abut what might cause this are welcome.

Really nice work on the core!!!!!!!!

Attiny13_nrf_microcore.zip (7.07 KB)