Archives for category: Used Software

Starting to program microcontrollers in assembler is quite a barrier in the beginning. Searching the web for Assembler tutorials and example code can get confusing really fast, that’s why I want to share my experiences and provide a collection of links that helped me to get started with this topic.

First of all three important differences derive from the three major microcontroller companies: Microchip, Atmel and ARM. Good introduction to Microcontrollers (also for the difference of PIC and AVR) and also this basic Introduction into Assembly Language and a Assembler Hello World ASM Example are worth having a look.

Further there are ways to convert C code to Assembler code, to optimize C code for AVR microcontrollers by Atmel and ways to mix these languages together: Mixing C and Assembly, Atmel tutorial for Mixing C and Assembly

The difference between the .asm and .S file extensions for the assembler code files is not really clear, but this messageboard thread about the file extensions difference of .ASM and .S helped a little bit. Two examples for .S-files can be found with a Linker Script commands for S-code blink example and another S-code blink example. More infos on Linker Scripts here.

Besides the instruction sets and specific libraries for the microcontrollers it is important to understand how the GNU GCC Compiler works. For example does it use the GNU Binutils for i.a. compile command objcopy etc. Here can also be found some compile commands for my AVRFID example.

If you find anything wrong in this collection of informations on microcontroller programming, I would be happy for a comment. I wanted to sum up and share my search results here and maybe it helps other people to get faster into it!?

  1. 21. September 2008: Using an AVR as an RFID tag by Author Beth (Micah Dowty) and version 1.0 of the avrfid.S . Also found as the Emulator RFID.
  2. 15. June 2010: AVRFID 1.1 Firmware by Author Beth (Micah Dowty) version 1.1 of the avrfid.S which incoporates a few patches by Luke Koops who improved the FSK modulation for HID tags, so that the resulting waveform is much more regular and Cesar Fernandez who described the HID card format in more detail.
  3. 16. May 2011: Duct Taped AVRFID by Author Beth (Micah Dowty) uses her version 1.1 avrfid.S
  4. November 2011: AVRFID PCB Implementation by Daniel Smith
  5. September 2012: RFID Spoofing by Eric Barch who only uses Beth’s (Micah Dowty)  HID part of her version 1.1 avrfid.S .
  6. 1. December 2012: AVRFID 1.2 Firmware last update by Daniel Smith on his version 1.2 of Beth’s avrfid.S which adds support for 35 bit HID Corporate 1000 format and fixed 26 bit parity.
  7. 27. December 2012: AVR RFID Multipass by Trammell Hudson of the NYC Resistor hacker collective, which come up with an optimized version of Beth’s version 1.2 avrfid.S and convert it to C ending in the avrfid2.c file. Beth (Micah Dowty) welcomes this transition as it uses less of the 8kB flash memory of the AVRs etc… and has an nice application scenario of an action figure, whose body parts trigger different IDs in the AVRFID tag. The whole code in C for latest AVRFID tag and the reader can be found here. In his post Hudson also describes how easy it is to reprogramm AVRs with some Bus Pirate Tools, which provide an recovery clock. But a few patches are still needed!

The T5557 protocol by Atmel supports read and write operations on RFID tags. Here a shorter summary of the T5557 protocol. By that it’s easy to clone tags, like in this example. But at the same time this rises security issues, which is probably the reason why it is not so commonly used (yet). The difference to the successor, the T5567 protocol is simply some improvements in terms of power on reset if the tag enters the field very slowly.

Really comprehensive explaination of the EM4100 protocol. The whole data structure of this common communication is illustrated, which also gives me orientation for the demands on my custom AVRFID code. Here the official EM4100 datasheet which is part of a whole family of EM protocols by EM Microelectronic. There is also an overview of their protocols by the field of application. The latest protocol is the EM4200 which actually replaces the precursor protocols EM4100/4102 and EM4005/4105.

I have spent quite some time to get the serial communication between Processing and Arduino working. Unfortunately I haven’t succeeded yet. It’s either some vagabonding libraries or a 64bit incompatibility issue. The only information according this error was in the Processing wiki and in a messageboard thread. They recommend to manually replace some jars and dlls, but their troubleshootings didn’t work yet. I still have to try another specially 64bit compiled version of the RXTX library. I watched thru several serial communication tutorials (1,2,3,4,5), hoping to find some more informations according this error. I also stumbled over the CmdMessenger Library, which sounds like a interessting solution for the serial communication (CmdMessenger on GitHub). I also got the Eclipse plugin for Processing, but the same here. Right now I don’t know, if I should just put a fresh Windows version on my pc or if I should keep on trying to solve that error elsewise! So for the moment, I stepped back to the Arduino Code which already worked but hasn’t had the perfect formatting of the IDs in decimal.

I tried to get the formatting of the hex ID data right, but I was quickly confronted with the limitations of the arduino microcontroller chip. Having a good debugging with a lot of strings and implementing the ASCII table as an array, was to much for the 2 KB RAM of the Arduino Uno. Now I have installed Simple Digital Firmata and will do the debugging and formatting computation in processing. More to come…

AVR (ATtiny85) Installation & Programming Guide (this worked for me!):

  • Using Win7 64bit get this Driver for the ‘Sparkfun AVR Pocket Programmer’. Make sure you have the ‘Sparkfun AVR Pocket Programmer’ connected via USB to your PC and remember the usb port, as you should always connect the ‘Sparkfun AVR Pocket Programmer’ to the same port. That probably was the reason why I had to install it several times until my PC recognized the ‘Sparkfun AVR Pocket Programmer’. If you got the “rc=-1 error“, there is something wrong with the driver or in finding the right USB port. It might as well be a wrong wiring of the ATtiny!
  • Further install AVRDude/WinAVR. Here an overview about drivers and software.
  • Besides WinAVR you can directly programm AVRs out of the Eclipse IDE with the following plugin.
  • REALLY TRIPLE CHECK THE WIRING of the ATtiny85 according to the data sheet, tutorials (1, 2, 3, 4, 5, 6) and this fritzing scheme. More details in the next post.
  • Setting up an AVR project: In the Eclipse Project Explorer do ‘New > Project > C-Project > AVR Cross Target Application > Empty Project (notice the AVR-GCC Toolchain) > Select ATtiny85 as AVR Target Hardware Properties.’
  • Make a new C-File and copy some ‘Blink’ test code or write some code on your own. A look into the AVR Library Reference ain’t wrong, too! As well as knowing how the bit manipulation operators in c-code work.
  • Compile your C-Files. In Eclipse just go to ‘Project > Build All’. With the consol use following commands. Make sure to be in the right directory of the C-File, which you want to compile etc.
  • Uploading/Flashing the HEX-File onto the ATtiny85 worked with the AVR Eclipse Plugin and adjusting following project preferences: Select your C-Project and then go on ‘File > Properties > AVR > AVRDude > Programmer > Programmer configurations > new > Select USBtiny simple USB programmer’ as the Programmer Hardware and select your new Programmer in the programmer configuration drop down menu. Right next to the ‘Programmer’ tab go on the ‘Flash/ EEPROM’ Tab and select ‘from flash memory image file’ for the ‘Upload Flash Memory Image’. Now browse and select the according HEX-File. Make sure the right project is still selected and go on ‘AVR > Upload Project to Target Device’. Should work, good luck!

Related Github Code Repository

Here you can find most of the code I used. Also check out the Github of my superviser Auérlien. In the course of that, I also installed TortoiseGit for an easier commit/push of code into my Github repository.