mirror of
https://codeberg.org/scip/attinycore-makefile-tests.git
synced 2025-12-16 19:00:57 +01:00
add
This commit is contained in:
1
841-tinycore-micronucleus-vcc-header-test/841vcc.h
Symbolic link
1
841-tinycore-micronucleus-vcc-header-test/841vcc.h
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../mylibs/841vcc.h
|
||||||
53
841-tinycore-micronucleus-vcc-header-test/Makefile
Normal file
53
841-tinycore-micronucleus-vcc-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)
|
||||||
17
841-tinycore-micronucleus-vcc-header-test/README.md
Normal file
17
841-tinycore-micronucleus-vcc-header-test/README.md
Normal file
@@ -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)
|
||||||
|
```
|
||||||
93
841-tinycore-micronucleus-vcc-header-test/SensorSerial.ino
Normal file
93
841-tinycore-micronucleus-vcc-header-test/SensorSerial.ino
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/* -*-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"
|
||||||
|
|
||||||
|
#define NODE_ID 1
|
||||||
|
#define OUTPUT_PIN 7
|
||||||
|
#define LED 2 //LED_BUILTIN // PORTB2
|
||||||
|
#define CS 3
|
||||||
|
#define DELAY 2000
|
||||||
|
|
||||||
|
#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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
print_measurements();
|
||||||
|
delay(DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
1
841-tinycore-micronucleus-vcc-header-test/hardware
Symbolic link
1
841-tinycore-micronucleus-vcc-header-test/hardware
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware
|
||||||
47
mylibs/841vcc.h
Normal file
47
mylibs/841vcc.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Macros for easier usage of vcc measurements.
|
||||||
|
For attiny8441 only.
|
||||||
|
|
||||||
|
We use REFS=0 to select VCC as Reference. i.e. ADMUXB = 0 << REFS0
|
||||||
|
We then use channel #13 to read the BandGap. i.e. ADMUXA = 13 << MUX0
|
||||||
|
|
||||||
|
And calculate the value of VCC from the reading. i.e. ADCW / 1024 = 1.1 / VCC
|
||||||
|
Rearrange i.e. VCC = 1.1 * 1024 / ADCW
|
||||||
|
|
||||||
|
Thanks for the help of the guys at AVR-Freaks:
|
||||||
|
https://www.avrfreaks.net/forum/measuring-vcc-attiny841-using-adc-and-internal-bandgap
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
#ifndef VCC_8441_H
|
||||||
|
#define VCC_8441_H
|
||||||
|
|
||||||
|
// disable ADC globally
|
||||||
|
#define adc_disable() ADCSRA &= ~(1<<ADEN)
|
||||||
|
|
||||||
|
// enable
|
||||||
|
#define adc_enable() ADCSRA = (1<<ADEN); _delay_ms(10);
|
||||||
|
|
||||||
|
// use supply voltage VCC as reference
|
||||||
|
// measure internal bandgap 1v1 voltage reference
|
||||||
|
// via channel 13, see table 16-3
|
||||||
|
// and do not left shift result
|
||||||
|
#define adc_setup_vcc_measurement() \
|
||||||
|
ADMUXB = (0<<REFS0); \
|
||||||
|
ADMUXA = (13<<MUX0); \
|
||||||
|
ADCSRB = (0<<ADLAR);
|
||||||
|
|
||||||
|
// start measurement
|
||||||
|
// and wait till complete
|
||||||
|
#define adc_start() \
|
||||||
|
ADCSRA |= _BV( ADSC ); \
|
||||||
|
while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
|
||||||
|
|
||||||
|
// return measured voltage
|
||||||
|
// >> 1.1 * 1024 / 225 #=> 5.006222222222223
|
||||||
|
// >> 1.1 * 1024 / 341 #=> 3.3032258064516133
|
||||||
|
#define adc_get_vcc() 1.1 * 1024 / ADCW;
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user