Friday 8 February 2013

RFM12B shield for Raspberry Pi

RFM12B and Atmel ISP programmer shield for Raspberry Pi
RFM12B shield for Raspberry Pi, with integrated in-circuit serial programmer.
Click on the image for an annotated version. 

I recently described the preliminary design of a RFM12B shield for the Raspberry Pi, which used an Atmel ATmega328 to interface between the Raspberry Pi's UART and the RFM12B's SPI interface. The design also included a buffered two-channel in-circuit serial programmer (ISP) using the Raspberry Pi's general purpose I/O. The first channel is for programming the on-board ATmega328 whilst the second channel can program external microcontrollers.

The boards have now been manufactured and the first one assembled and tested. The interface to the RFM12B and the built-in AVR ISP programmer both work as designed. I have been using the Arduino environment to compile and upload the firmware to the ATmega328. The microcontroller pin mapping is identical to the Arduino Uno although the activity LED is wired to D9 since D13 is normally in use by the SPI interface. The ATmega328 operates at 3.3V and is clocked by the internal 8MHz RC oscillator. No bootloader is needed. The Github repository contains boards.txt and programmers.txt files for use with the Arduino IDE, the standard Arduino core is used.

I have been using the first board to replace a Ciseco URF radio module. The firmware for the ATmega328 incorporates my transparent serial emulation layer. This provides a Stream object to which data can be read, and written (or printed), in just the same way as HardwareSerial and SoftwareSerial objects. The same emulation layer can then be used on remote Calunium, Arduino or JeeNode boards to provide a bi-directional data stream, allowing the user to interface to the RFM12B as easily as an XRF or XBee radio module. The emulation layer transparently uses acknowledgements and retries to provide a robust channel, which is an improvement over the Ciseco XRF and URF radio modules. Alternative firmware for the RFM12B shield is easily uploaded to provide different functionality.

ISP programmer

The avrdude configuration file contains details for two GPIO programmers; gpio0 is connected to the on-board ATmega328 and gpio1 is for programming external microcontrollers. By fitting a jumper to the JP1 header the external microcontroller can be powered from the Raspberry Pi's 3.3V supply. Be sure to observe the maximum current rating for the 3.3V supply and never fit the jumper if the remote microcontroller is self-powered. The 74LVC244 buffer ensures that MCUs operating at 5V can be safely connected. Typically the high output level from the 74LVC244 buffer will be recognised as a high but it doesn't meet the worst-case specifications when the external MCU is powered from 5V.

Open source

The Eagle PCB design files for the RFM12B/ISP shield for Raspberry Pi are available on Github and are licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. The RF12 transparent serial emulation layer is also available on Github and is released under the MIT license.

Errata

There is a connection missing on the schematic from the drain of FET Q2 to pin 5 (/RESET) on the external ISP header (X3). This connection is also missing from the PCB but can be easily fixed with a direct wire connection on the underside of the board.

Update

I've added a description of how to install and use the patched version of avrdude, http://blog.stevemarple.co.uk/2013/03/how-to-use-gpio-version-of-avrdude-on.html.

17 comments:

  1. Is there a set PCB files with the missing track fixed?

    ReplyDelete
    Replies
    1. The Eagle files can be found at https://github.com/stevemarple/RPi_RFM12B_ISP/tree/master/hardware/v1.1
      I haven't generated the Gerber files yet but that is easy to do. I just noticed that the design rule file (.dru) that I used previously isn't in the project directory. I'll correct that omission and add the Gerber files when I get time; might be a few days.

      Delete
    2. I've uploaded the Gerber files for the version which fixes the missing reset line. If you have any boards made please let me know how they work since I haven't sent this version off to production.

      Delete
  2. Thanks for updating the files.

    ReplyDelete
  3. I try to read the serial port: "sudo mini com -b 115200 -o -D /dev/ttyAMA0". I get garbage data. Baudrate of sketch vs Pi has been checked and are the same. Also disabled Hardware flow control. All to no avail. Any hints or someone with the same experience how resolved this? Many thanks!

    ReplyDelete
    Replies
    1. Can you give more information about the hardware you are using, and what sketch is running on the ATmega328? What value are the fuses set to? With this design the ATmega328 runs at 8MHz using the internal RC oscillator, which differs from the standard Arduino (16MHz crystal oscillator).

      Delete
    2. Hi Steve, sure. I run the RF12DEMO sketch from jeeLabs with serial port set to 57600 baud. Ofcourse I use your board on top of a Raspberry Pi model B with one of the latest Raspbian images. I've modified the /etc/inittab and /boot/cmdline.txt files to disconnect /dev/ttyAMA0 from console. I've used the ATMEGA328P-PU as controller chip and using the programmer through gpio with the modified avrdude works flawless. Fuses are set: lfuse:E2, hfuse:DA, efuse:FF Thanks for your help! Great board you've developed here!

      Delete
    3. That baud rate contradicts with the minicom command you posted earlier.
      Your fuse settings will have the ATmega328P using its 8MHz RC oscillator - are you sure you had the processor speed set to 8MHz when compiling the RF12DEMO sketch?
      One thing I noticed with your fuse settings is they indicate a 1KB bootloader. That's fine if you are using a bootloader and uploading programs via the serial port. If you're not you should adjust the fuses otherwise program execution will jump to the wrong place after reset. My boards.txt file is intended to upload sketches via the ISP interface. That avoids the problem of rebooting the ATmega328P just before sending serial data so that you can talk to the bootloader. You can find the correct fuse settings in the that boards file. I also enable brownout detection since I've had bad experiences of not using it (see http://blog.stevemarple.co.uk/2013/02/the-importance-of-brown-out-detection.html)

      Delete
  4. Thanks Steve. The minicom example I wrote was wrong but used the right baud rate in the actual exercise ;-) I'm not sure what you mean setting the right processor speed at compile-time. Never done that nor seen that. But will investigate. I use avrdude to program the processor and don't need the boot loader; I will reset the fuses indeed. Thanks for the hints, will report back as soon as I have results.

    ReplyDelete
    Replies
    1. If you use the Arduino IDE to compile and select the standard Arduino DueMilanov or Uno then the compiler will use 16 not 8MHz as the CPU clock speed. Having the speed set right is essential for the correct calculation of delays and for initialising the UART to set the baud rates.

      Delete
  5. Reset the fuses to E2,D1,05 as mentioned in the boards.txt. Reprogrammed the chip with -e erase option through avrdude. And... still garbage on the serial port. Only thing I couldn't figure out was setting the clock-frequency at compile time as you mentioned... Will google further ;-)

    ReplyDelete
  6. Hi Steve, all's fine now. Took same time to investigate why de board.txt did not do anything in the IDE as that seemed to be the clue to the right clock speed compile setting... I've IDE version 1.5.6 and googling learned me that the right folder structure should be: /hardware/raspi/avr/. Compiling wight the right board did the job! Thanks for your help!!

    ReplyDelete
  7. Steve, wanted to send you a big compliment on a great product you've created. The board has been in use at my site for a few weeks now and I'm loving it! Many thanks.

    ReplyDelete
  8. Hi, using the JeeLabs RF12demo sketch works fine except it doesn't hold the configuration changes it writes the eeprom after a power-cycle. Sketch works fine on other boards like Moteino and JeeNode with the same ATMEGA328p-pu. Any clues on how to investigate this further and what specifics of this board could be causing this behaviour? Thanks!

    ReplyDelete
    Replies
    1. It sounds like you need to activate the "Preserve EEPROM memory through the Chip Erase cycle" (EESAVE) fuse to get the behaviour you desire. See the AVR fuse caclulator, http://www.engbedded.com/fusecalc/.

      Delete
  9. Hi Steve, thanks for your consideration.

    fuses are set as follows lfuse: 0xe2, hfuse: 0xd1, efuse: 0x05

    This gives a positive on EEFUSE... I'm not going through a chip erase cycle rather a reboot cycle. So still confused as to what causes this behaviour.

    ReplyDelete
    Replies
    1. Sorry, I misread your comment about the power-cycle. I don't see why the cycling the power should erase the EEPROM, are you sure it was actually written correctly, can you please check that is the case? The board is powered from the Pi's 3V3 output, which has a low current limit (50mA?). I don't think that should be a problem but it might depend what else is taking current when the EEPROM writing occurs. Is the RFM12 in standby mode when writing to the EEPROM, that might help.

      Delete

Note: only a member of this blog may post a comment.