Happy Christmas and Happy New Year wishes from Attiny13

Summary of Happy Christmas and Happy New Year wishes from Attiny13


The author salvaged a damaged Chinese camera pen's SPI flash memory and repurposed it into an 8K mono audio player using an Attiny13 microcontroller. Despite the chip's limited 1KB flash and 64 bytes RAM, the project successfully plays one-minute wav files by utilizing software SPI for memory access, a PWM pin for audio output, and UART for song updates. The design creatively reassigns pins to accommodate eight functional requirements within the device's five available GPIOs.

Parts used in the Attiny13 Audio Player:

  • LE25U40CMD SPI flash memory
  • TI Stellaris Launchpad
  • Attiny13 microcontroller
  • PWM pin (PB0)
  • SPI pins (SO, SI, CS, SCK)
  • UART communication interface
  • Switch for song loading mode
  • USB to UART converter or RS232 port
  • MAX232 circuit
While trying to open a chinese camera pen, unfortunately the PCB inside it got damaged. Few of the PCB traces got cut and it became useless. After few days, I removed an 8 pin IC with SO8 package from the PCB. I was curious to know what it is, so I googled the part number 25FW406A but I couldn’t find any exact match. I found some part number similar to that and I concluded that it is an SPI flash. Later I got a datasheet from ‘ON semiconductor’ for a similar part -LE25U40CMD which is a 4M-bit SPI flash memory. I soldered the IC on a common board, powered it with 3.3v and interfaced it to a TI stellaris launchpad via SPI port. According to the datasheet the SPI port need to be initialized in mode 0 or 3. I tried few commands listed in the datasheet and got proper response from the chip, the CHIP ID doesn’t matches but that is expected because it is not the same part. I wrote functions for erasing, reading and writing the flash memory and tested it successfully using the launchpad.
Happy Christmas and Happy New Year wishes from Attiny13
       Then I thought of making an audio player using this chip which can play 8K mono wav file for around 1 minute. I selected Attiny13 microcontroller for this project. It is always fun to do some thing with limited resources. Attiny13 MCU is having 1KB flash and 64 bytes RAM. Also it is an 8 pin MCU. There are 5 GPIOs. I don’t want to change the reset pin as a GPIO because I want to program it via ISP while developing the firmware.
       My requirements are,
            1> One PWM pin for audio out. [1 pin]
            2> SPI pins for interfacing with flash memory. (SO, SI, CS, SCK) [4 pins]
            3> UART communication for song update. [2 pins]
            4> Switch to select song loading mode [1 pin]

So all together 8 pins are required. But the controller have only 5 GPIOs. Out of this, PB0 is used as PWM for audio out. So I cannot use hardware SPI because PB0 is the MOSI pin for hardware SPI. So no other option, I have to use software SPI but it is not a problem. I used the other 4 pins for SPI. To update song in memory chip, I thought of using UART because it is the most popular way of communication between microcontroller and a PC, also most electronics hobbyist will have one usb to uart converter or an RS232 port and a MAX232 circuit. I used the same PWM pin as UART RX because it is having pin change interrupt feature. Also while flashing wav file, I don’t want to use the PWM function. Also it is the only free PIN which is not connected to the SPI port of the memory chip. Now I need a TX pin for sending ACK to the programmer and for proper handshaking while loading the song to memory chip. I used the SCK pin for this purpose. But SCK pin will toggle while communicating with the memory,
 
For more detail: Happy Christmas and Happy New Year wishes from Attiny13

Quick Solutions to Questions related to Attiny13 Audio Player:

  • What type of flash memory was recovered from the camera pen?
    The component is identified as a 4M-bit SPI flash memory similar to the LE25U40CMD.
  • How many GPIOs does the Attiny13 microcontroller have?
    The Attiny13 has five GPIOs available for general use.
  • Why was software SPI chosen instead of hardware SPI?
    Software SPI was required because the PB0 pin needed for hardware SPI MOSI was reserved for the audio PWM output.
  • How are songs updated to the flash memory?
    Songs are updated using UART communication via a USB to UART converter or RS232 port with a MAX232 circuit.
  • Which pin is used for sending ACK signals during song loading?
    The SCK pin is reused as a TX pin to send acknowledgments and handle handshaking while updating the file.
  • What audio format and quality does the player support?
    The player supports 8K mono wav files that can play for approximately one minute.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top