Series
ATmega328P from scratch
Flashing the chip directly: pins, interrupts, timers, buses and sensors, with no Arduino library in the way.
12 parts, in reading order
- 01Bare metal on the ATmega328P: pins, fuses and a first blinkPart 1: making a pin an output, and the fuse setting that decides whether the chip runs at 16 MHz, at 1 MHz, or not at all.
- 02UART: giving the chip a voice on one wirePart 2: a serial channel out of the chip, the four settings both ends must agree on, and what a baud mismatch looks like on an analyser.
- 03ADC: turning a voltage into a numberPart 3: reading a potentiometer with the ATmega328P's 10-bit converter, and the prescaler setting that decides how accurate the answer is.
- 04Interrupts: two ways to let hardware call your codePart 4: a button on INT0 and the same button on a pin-change interrupt, the rules an ISR has to follow, and the one line people forget.
- 05Timers: accurate time without delay loopsPart 5: the chip's built-in counters, CTC versus overflow, and a watchdog that resets the chip when the program hangs.
- 06PWM: switching too fast to seePart 6: using Timer1 to make a pin flicker faster than the eye can follow, and letting a potentiometer set the duty cycle.
- 07Servos: when pulse width is a positionPart 7: a 50 Hz signal where the width of each pulse is the angle, and the power wiring that decides whether it moves or jitters.
- 08SPI: two chips passing notesPart 8: a four-wire bus with a shared clock, two ATmega328Ps exchanging bytes, and the reason a send is always also a receive.
- 09What a logic analyser shows on an SPI busPart 9: reading a real capture of two chips talking, from the chip-select frame to the byte the slave sends one transaction late.
- 10SPI in practice: a 25LC512 EEPROM driverPart 10: writing a real SPI device driver, with write-enable, status polling and the page boundary that silently wraps your data.
- 11I2C: two wires and a roll callPart 11: a shared bus with addresses and acknowledgements, a repeated start, and a driver that reads an MPU6050 over it.
- 12DHT11: a protocol built out of delaysPart 12: reading a temperature sensor with nothing but pin toggling and microsecond timing, and the comment in the source that has it backwards.