mirror of
https://codeberg.org/scip/attinycore-makefile-tests.git
synced 2025-12-18 03:30:57 +01:00
added
This commit is contained in:
1
841-tinycore-micronucleus-vcc-sleepmode-header-test/841sleep.h
Symbolic link
1
841-tinycore-micronucleus-vcc-sleepmode-header-test/841sleep.h
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../mylibs/841sleep.h
|
||||||
1
841-tinycore-micronucleus-vcc-sleepmode-header-test/841vcc.h
Symbolic link
1
841-tinycore-micronucleus-vcc-sleepmode-header-test/841vcc.h
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../mylibs/841vcc.h
|
||||||
53
841-tinycore-micronucleus-vcc-sleepmode-header-test/Makefile
Normal file
53
841-tinycore-micronucleus-vcc-sleepmode-header-test/Makefile
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
|
||||||
|
|
||||||
|
# attiny841:
|
||||||
|
# BOARD_TAG = attinyx41
|
||||||
|
# BOARD_SUB = 841
|
||||||
|
# attiny861:
|
||||||
|
# BOARD_TAG = attinyx61
|
||||||
|
# BOARD_SUB = 861
|
||||||
|
# attiny85:
|
||||||
|
# BOARD_TAG = attinyx5
|
||||||
|
# BOARD_SUB = 85
|
||||||
|
# attiny84:
|
||||||
|
# BOARD_TAG = attinyx4
|
||||||
|
# BOARD_SUB = 84
|
||||||
|
|
||||||
|
ARDUINO_VERSION = 10810
|
||||||
|
|
||||||
|
PROJECT_DIR = $(shell pwd)
|
||||||
|
BOARD_TAG = attinyx41
|
||||||
|
BOARD_SUB = 841
|
||||||
|
ARDUINO_DIR = /usr/local/arduino
|
||||||
|
ARDMK_DIR = /usr/local/arduino/Arduino-Makefile
|
||||||
|
MONITOR_PORT = /dev/ttyACM0
|
||||||
|
ISP_PORT = /dev/ttyACM0
|
||||||
|
AVRDUDE = /usr/local/bin/avrdude
|
||||||
|
ARDUINO_LIBS =
|
||||||
|
ARDUINO_SKETCHBOOK = .
|
||||||
|
|
||||||
|
# mk stuff
|
||||||
|
ALTERNATE_CORE = ATTinyCore
|
||||||
|
F_CPU = 8000000L
|
||||||
|
MONITOR_BAUDRATE = 115200
|
||||||
|
AVRDUDE_ARD_PROGRAMMER = stk500v2
|
||||||
|
AVRDUDE_ARD_BAUDRATE = 9600
|
||||||
|
AVR_TOOLS_DIR = /usr/local/avr
|
||||||
|
AVRDUDE_CONF = /usr/local/etc/avrdude.conf
|
||||||
|
|
||||||
|
# Micronucleus
|
||||||
|
MNINST = sudo micronucleus
|
||||||
|
|
||||||
|
# compiler stuff
|
||||||
|
CFLAGS_STD = -std=gnu11
|
||||||
|
CXXFLAGS_STD = -std=gnu++11
|
||||||
|
CXXFLAGS + = -pedantic -Wall -Wextra
|
||||||
|
CURRENT_DIR = $(shell pwd)
|
||||||
|
|
||||||
|
# keep this!
|
||||||
|
include $(ARDMK_DIR)/Arduino.mk
|
||||||
|
|
||||||
|
# install using micronucleus
|
||||||
|
install: $(TARGET_HEX) verify_size
|
||||||
|
@echo "########### Press RESET on the Nanite! ##############"
|
||||||
|
$(MNINST) $(TARGET_HEX)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Usable Pins
|
||||||
|
|
||||||
|
```
|
||||||
|
PIN_A0 (10)
|
||||||
|
PIN_A1 ( 9)
|
||||||
|
PIN_A2 ( 8)
|
||||||
|
PIN_A3 ( 7)
|
||||||
|
PIN_A4 ( 6)
|
||||||
|
PIN_A5 ( 5)
|
||||||
|
PIN_A6 ( 4)
|
||||||
|
PIN_A7 ( 3)
|
||||||
|
PIN_B0 ( 0)
|
||||||
|
PIN_B1 ( 1)
|
||||||
|
PIN_B2 ( 2)
|
||||||
|
PIN_B3 (11) /* RESET */
|
||||||
|
LED_BUILTIN (2)
|
||||||
|
```
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/* -*-c++-*-
|
||||||
|
Blink
|
||||||
|
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||||
|
This example code is in the public domain.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
./hardware/ATTinyCore/avr/cores/tinymodern/core_pins.h
|
||||||
|
Caution: reverse Pinout: PA3 => Pin 3
|
||||||
|
|
||||||
|
Nanite841 Pinout from above:
|
||||||
|
|
||||||
|
button
|
||||||
|
SDO/MISO PA5 PA6 SDI/MOSI
|
||||||
|
SCK PA4 PA7
|
||||||
|
CS PA3 PB2
|
||||||
|
RX0 PA2 PB2
|
||||||
|
TX0 PA1 PB1
|
||||||
|
PA0 PB0
|
||||||
|
GND VCC
|
||||||
|
usb
|
||||||
|
|
||||||
|
Bosch BME280 Breakout from above pin header left:
|
||||||
|
|
||||||
|
VCC
|
||||||
|
GND
|
||||||
|
SCL => SCK
|
||||||
|
SDI => MOSI
|
||||||
|
CSB => PA3/3
|
||||||
|
SDO => MISO
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include "841vcc.h"
|
||||||
|
#include "841sleep.h"
|
||||||
|
|
||||||
|
#define NODE_ID 1
|
||||||
|
#define OUTPUT_PIN 7
|
||||||
|
#define LED 2 //LED_BUILTIN // PORTB2
|
||||||
|
#define CS 3
|
||||||
|
#define DELAY 1000
|
||||||
|
#define WDTREPEATS 3
|
||||||
|
|
||||||
|
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
||||||
|
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
||||||
|
#define SET_LOW(pin) PORTB &= ~(1 << pin)
|
||||||
|
|
||||||
|
void print_asufloat(uint32_t val, uint16_t factor) {
|
||||||
|
Serial.print(val / factor);
|
||||||
|
Serial.print(".");
|
||||||
|
Serial.print(val % factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_asifloat(int32_t val, uint16_t factor) {
|
||||||
|
Serial.print(val / factor);
|
||||||
|
Serial.print(".");
|
||||||
|
Serial.print(val % factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_measurements() {
|
||||||
|
float vcc;
|
||||||
|
|
||||||
|
SET_LOW(LED);
|
||||||
|
|
||||||
|
adc_enable();
|
||||||
|
adc_start();
|
||||||
|
vcc = adc_get_vcc();
|
||||||
|
adc_disable();
|
||||||
|
|
||||||
|
Serial.print("Voltage: ");
|
||||||
|
Serial.println(vcc);
|
||||||
|
|
||||||
|
SET_HIGH(LED);
|
||||||
|
}
|
||||||
|
|
||||||
|
void halt() {
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
SET_OUTPUT(LED);
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("init");
|
||||||
|
|
||||||
|
adc_setup_vcc_measurement();
|
||||||
|
sleep_setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
uint8_t i;
|
||||||
|
print_measurements();
|
||||||
|
delay(DELAY);
|
||||||
|
for(i=0; i<WDTREPEATS; i++) {
|
||||||
|
Serial.print("----- ENTER SLEEP: ");
|
||||||
|
Serial.println(i);
|
||||||
|
sleep_enter();
|
||||||
|
Serial.println("----- LEAVE SLEEP");
|
||||||
|
}
|
||||||
|
Serial.println("-- DONE");
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep_vect();
|
||||||
|
|
||||||
1
841-tinycore-micronucleus-vcc-sleepmode-header-test/hardware
Symbolic link
1
841-tinycore-micronucleus-vcc-sleepmode-header-test/hardware
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware
|
||||||
57
mylibs/841sleep.h
Normal file
57
mylibs/841sleep.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
Macros for easier sleep mode management
|
||||||
|
For Attiny841 only
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/sleep.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
#include "841vcc.h"
|
||||||
|
|
||||||
|
#ifndef SLEEPMODE_8441_H
|
||||||
|
#define SLEEPMODE_8441_H
|
||||||
|
|
||||||
|
#ifndef SLEEPMODE
|
||||||
|
#define SLEEPMODE SLEEP_MODE_PWR_DOWN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SLEEP_DURATION_BITS
|
||||||
|
#define SLEEP_DURATION_BITS (_BV(WDP0) | _BV(WDP3)) // 8s
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// define sleep mode
|
||||||
|
// disable analog comparator 0 and 1
|
||||||
|
// disable SPI
|
||||||
|
// unlock Watchdog configuration register
|
||||||
|
// enable the WD interrupt, set watchdog timeout prescaler value (interrupt period)
|
||||||
|
// unlock clock configuration change
|
||||||
|
// change clock prescaler to 8
|
||||||
|
#define sleep_setup() \
|
||||||
|
set_sleep_mode(SLEEPMODE); \
|
||||||
|
ACSR0A |= _BV(ACD0); \
|
||||||
|
ACSR1A |= _BV(ACD1); \
|
||||||
|
CCP = 0xD8; \
|
||||||
|
WDTCSR = _BV(WDIE) | SLEEP_DURATION_BITS; \
|
||||||
|
CCP = 0xD8; \
|
||||||
|
CLKPR = (_BV(CLKPS0) | _BV(CLKPS1));
|
||||||
|
|
||||||
|
// FIXME: check!
|
||||||
|
// PRR = 0xFF;
|
||||||
|
|
||||||
|
|
||||||
|
// go into sleep mode and wake up after wtd timeout
|
||||||
|
// also disable SPI
|
||||||
|
#define sleep_enter() \
|
||||||
|
adc_disable(); \
|
||||||
|
SPCR &= ~_BV(SPE); \
|
||||||
|
sleep_enable(); \
|
||||||
|
sleep_mode(); \
|
||||||
|
sleep_disable(); \
|
||||||
|
SPCR = (1<<SPE)
|
||||||
|
|
||||||
|
// nothing extra to do on wake up, just wake up
|
||||||
|
#define sleep_vect() ISR(WDT_vect){}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user