I'm just an enthusiast looking for some advice.

I'd like to use a microcontroller to read frames from a camera and write those frames to a small LCD screen. The camera and screen are on the same SPI bus. I've been prototyping with an Arduino but I'd like to move to an AVR eventually.

Problem is, an image frame is 9600 bytes and the Arduino SRAM is 2.5KB. I can't buffer a whole frame. I tried reading from camera and writing to the screen a few lines at a time, but because they are on the same SPI bus, I need to de-assert the camera, assert the screen, and then re-assert the camera. If you de-assert the camera mid-frame you lose sync.

I need to figure out a way to get 9600 bytes from camera to screen without de-asserting the camera. Seems like I have 2 options: Increase SRAM to buffer a frame or separate SPI busses.

Increase SRAM:

  • Change AVRs - The only ATmega with enough SRAM is ATmega1284 and it's got 44 pins.
  • External SRAM? Never worked with it.

Separate SPI busses:

  • Move screen from hardware SPI to regular pins and write software SPI. (I doubt this would be fast enough.
  • Looks like there are several ATtinys and ATmegas with 2 or more SPI busses. Some as small as 20 pins. This would still delay the reading of single frames, but hopefully not too much.

Something... else?

  • FPGA? Never worked with them...
  • Some other type of microcontroller?


  • 1
    \$\begingroup\$ Software SPI might well be fast enough. SPI is a very simple protocol, so it shouldn't take long to try it and find out. \$\endgroup\$ Commented Oct 18, 2014 at 5:40
  • \$\begingroup\$ A Cortex-M0 in a DIP8 package with 3x USART + 2x SPI: nxp.com/documents/data_sheet/LPC81XM.pdf \$\endgroup\$
    – markt
    Commented Oct 18, 2014 at 23:01
  • \$\begingroup\$ Page 3 shows DIP package with only 1 SPI. 3x USART + 2x SPI are only for TSSOP & XSON packages. \$\endgroup\$ Commented Oct 19, 2014 at 3:17
  • \$\begingroup\$ Meh, I should have read further. Still, it would be able to do what you need. \$\endgroup\$
    – markt
    Commented Oct 19, 2014 at 6:12

3 Answers 3


Something else (sort of):

Several of the ATmega devices can reconfigure their USART(s) to act as a SPI master. Simply connect one of the devices to one of these reconfigured peripherals. Look for "USART in SPI Mode" or "MSPIM" in the datasheet.

  • \$\begingroup\$ Based on this comment, I stumbled across Atmel's Product Search page. I had just be using digikey. It seems that ATMega328's have 2 SPI ports so I may just go with that. I have ATtiny85 and ATMega88A on hand so I'll see if I can configure their UART as SPI before I buy a 328. \$\endgroup\$ Commented Oct 18, 2014 at 15:53
  • \$\begingroup\$ The '88A is essentially identical to the '328 except for the amount of flash and RAM. The second SPI port is the reconfigured USART. \$\endgroup\$ Commented Oct 18, 2014 at 16:00
  • \$\begingroup\$ Also, ATtinyX5 only has the single USI, so I'd not look at that one for this. \$\endgroup\$ Commented Oct 18, 2014 at 16:02
  • \$\begingroup\$ Ah! So it is! It may be faster to buffer 2K at a time with the 328 instead of 1K with the 88A, but I will certainly try my 88A now. Thanks! \$\endgroup\$ Commented Oct 18, 2014 at 16:05

Try an STM32F4Discovery board; US$15-25. The MCU is an STM32F407VG: 168MHz ARM Cortex-M4, 1MB flash, 192kB RAM, 3 SPI ports and DMA that would, for example, allow you to stream from one SPI port to another with minimal processor involvement. The Discovery has a built in SWD programmer/debugger so no extra hardware is required; try CooCox for a free and unlimited IDE.

  • \$\begingroup\$ reference designs are available yes? People can make their own STM32F4 based boards quite easily using the reference designs and schematics? \$\endgroup\$
    – KyranF
    Commented Oct 18, 2014 at 9:08
  • \$\begingroup\$ I've made several. \$\endgroup\$
    – markt
    Commented Oct 18, 2014 at 10:06
  • \$\begingroup\$ are they nice and clean? I used the Atmel SAM3 Xplained development/reference board as an example for my Cortex M3 board and it was a mess, so many useless and silly extra things for their board and the code is similarly bloated \$\endgroup\$
    – KyranF
    Commented Oct 18, 2014 at 11:42
  • \$\begingroup\$ Thanks for the suggestion! This looks like a powerful tool. I'm not sure it fits the form factor I'd like to eventually move to, but it would certainly prove the concept. \$\endgroup\$ Commented Oct 18, 2014 at 15:46
  • \$\begingroup\$ @KyranF I don't use any of ST's library code, it's disgracefully bad imo, and I've barely looked at the Discovery schematics. I've (selectively but thoroughly) read the user and reference manuals and my boards have worked every time. There's nothing to be afraid of with Cortex-M's, they're just another microcontroller - but comparatively inexpensive and crazily powerful. \$\endgroup\$
    – markt
    Commented Oct 18, 2014 at 22:54

Most external RAM is SPI, which suffers from the same dual-bus problem you have already. That's not to say it's impossible to use.

A clever way would be to connect the camera's data output to the data input of an SPI SRAM chip and use the SRAM chip to directly capture the frame data. You could then access whatever part of the last frame received at your leisure. However, it would take a certain amount of cunning external circuitry to share the data input between the camera and your MCU, as they won't be able to be both connected at once, and you may also need to directly receive from the camera to set it up and check statuses etc (depending on the camera of course).

A simpler method would be to just use a bigger MCU.

PIC32 based boards would be a good alternative for the Arduino boards in this situation. Something like a chipKIT uC32 would give you 32KB of RAM, and multiple SPI ports, so you can both buffer a whole frame and use separate SPI ports. Also it's 32-bit and 80MHz so you can do processing of your data much much faster.

Also there are PIC32 boards which use 28-pin DIP chips (such as the DP32 which uses a PIC32MX150 chip) which is better for prototyping.

The IDE (MPIDE) and language are almost identical to Arduino, no nothing (much) new to learn.

  • \$\begingroup\$ Thanks for this. I presumed external RAM would be on SPI and therefore be a moot point; thanks for that confirmation. Your PIC32 suggestion does seem like it would accomplish the task, but not in my target form factor. (I've recently been seduced by the minimalism of 8-DIP ATTinys!) As I said in another comment, it looks like ATMega328 have 2 SPI ports in a DIP package, so I'll likely try that. \$\endgroup\$ Commented Oct 18, 2014 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.