ATtiny10 TMP36 and Serial

Its nice having serial for debug.. This was how I tested it after watching Ben Heck Hacks on youtube. It turned out great..

I hooked up to an FTDI serial connection and used CoolTerm to display results. I also tweeked the CTC a little different from Ben's 833 (but even he said he was going to tweek it. I found 808 worked best for me putting it right on 9.6khz. I've yet to get any garbage data.. The Serial works clean and has been very reliable.

/* * ATtiny10-ADC-tmp36-serial.c * Serial portion thanks to Ben Heck * * Works Great.. * * Created: 4/15/2022 11:30:14 * Author : Sherman Stebbins * * Attiny10 * +====+ * TX SCK -> PB0 |* | PB3 (RESET) * GND | | Vcc * MOSI -> PB1 | | PB2 TMP36 * +====+ * */ #define F_CPU 8000000UL#include <avr/io.h>#include <avr/interrupt.h>#include <util/delay.h>
static volatile char Xmit;static volatile uint8_t whichBitOut = 10;
void sendByte(uint8_t theByte){ Xmit = theByte; whichBitOut = 1; while(whichBitOut){} //wait for it to finish before another}
void print(const char *data){ while(*data != 0x00){ sendByte(*data++); }}
void printNum(uint16_t number){ uint8_t start=0; uint16_t divider = 10000; for(uint8_t i=0;i<5;i++){ if(number>=divider){ sendByte((number/divider)+48); number %= divider; start=1; }else if(start){ sendByte('0'); } divider /=10; }}
ISR(TIM0_COMPA_vect){ switch(whichBitOut){ case 1://start bit PORTB &= ~(1); //go low for start bit whichBitOut = 2; break; case 2 ... 9: if (Xmit & 0x01){ PORTB |= 1; }else{ PORTB &= ~(1); } Xmit >>= 1; whichBitOut++; break; case 10: PORTB|=(1); whichBitOut = 0; break; }
}
int main(void){ CCP = 0xD8; CLKPSR = 0b00000000; //no clock pre scale DDRB = 0b00001011; PUEB = 0b00000100; TCCR0A = 0b00000000; TCCR0B = 0b00001001; //set clock to 4 0100 CTC OCR0AH = 808 >> 8; // CTC = 8000000/9600 = 833.333333 OCR0AL = 808 & 0xFF; TIMSK0 |= (1<<OCIE0A); ADMUX = 0b00000010; //set adc to PB2; ADCSRA |=(1<<ADEN); //enable adc DIDR0 = (1<<ADC2D); //disable digital input pb2 sei(); uint16_t tmp=0; while (1) { _delay_ms(500); uint16_t avg=0; for(uint8_t i=0;i<20;i++){ ADCSRA |= (1<<ADSC); //start conversion while(ADCSRA & ADIF){} tmp = ADCL; avg+=tmp; } tmp=avg/20; tmp = ((((uint32_t)tmp * 1000UL) >> 10) * 5)+1; uint16_t tmpC=tmp; print(" C:"); printNum(tmp/10); tmpC=(tmp*180); //did 180 instead of 1.8 tmpC/=1000; //dropped back to 10 instead of 1000's tmpC+=32; print(" F:"); printNum(tmpC+3); print("\n"); // sendByte(13); // same as above // sendByte(10); }}


Actual size of ATtiny10.