Tamagotchi-like embedded device. As bare metal as possible.
To setup avr-gcc:
brew tap osx-cross/avrbrew install avr-gcc
To setup avrdude:
brew install avrdude
Check program size and memory usage:
avr-size build/main.elf
Make note of the $(PORT) definition, this is the USB port the MCU is plugged into. So this value will need to change depending on where it's plugged in. Use the Arudio IDE to identify the /dev path
I have included in docs/ the following:
- ATMega328P datasheet
- AVR architecture instruction set manual
- Pinout of the Arduino Nano clone board im using for prototyping
- Fritzing project file (very early WIP)
Links:
Datasheet notes:
- PRSPI bit may need to 0 to enable SPI, but this may only be for USART>SPI control...
- SPI master inits comm cycle when slave-select pin is pulled low
- Then master/slave prepare packet data in shift registers
- Master generates required SCK signal
- After each data packet, master syncs slave by pulling SS high
- No automatic control of SS when master
- Writing byte to SPI DR starts SCK generator, then 8 bits shifted to slave
- After shifting 1 byte, SCK generator stops and sets EOT flag in SPIF
- Request interrupt by setting SPIE bit in SPCR
- Continue to shift more bytes, or if done, signal end of packet with SS high
- Last byte is kept in buffer register for later
- Single buffer for transmit as master, must wait for shift cycle to complete before next byte in SPDR
| Board Function | Board Pin | AVR Pin | Direction | Screen Function | Notes |
|---|---|---|---|---|---|
| SS | D10 | PB2 | → | CS (chip select) | |
| MOSI | D11 | PB3 | → | SDI (serial data in) | This screen only has serial in, no ability to output SPI data |
| SCK | D13 | PB5 | → | CLK (clock) | |
| OC1A | D9 | PB1 | → | D/C (data/command) | |
| CLK/CP1 | D8 | PB0 | → | RES (reset) | |
| GPIO | D2 | PD2 | ← | BUSY (busy status) |
| Board Function | Board Pin | AVR Pin | Direction | Screen Function | Notes |
|---|---|---|---|---|---|
| SS | D10 | PB2 | → | CS | |
| MOSI | D11 | PB3 | → | Data | Only input to screen, ssd1306 has no data outs |
| SCK | D13 | PB5 | → | CLK | |
| OC1A | D9 | PB1 | → | A0 / DC | |
| CLK/CP1 | D8 | PB0 | → | RST | |
| ← | 3Vo | Screen provides 3V output, THIS IS NOT A BUSY SIGNAL |
| Board Function | Arduino Pin | AVR Pin | Direction | Device Function | Notes |
|---|---|---|---|---|---|
| GPIO | D12 | PB4 | → | Breadboard LED | The Arduino clone board has a built-in LED, but this is blocked during SPI comms |