Interface RFID module with Arduino UNO in pure Assembly language

Go To Last Post
37 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to interface RFID module with atmega m328p  in pure assembly code. I am not able to figure out , how to proceed?

 Anyone can provide the appropriate resources to study. I just want RFID module , no LCD . I can use the seven segment display.

I just want to know the basics of interfacing RFID in assembly language.

Raj

Last Edited: Sun. Nov 5, 2017 - 05:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, Raj666 -

 

What RFID unit is it? Nobody can help you without more information! Our crystal balls do not work very well without that information.

 

How does the RFID unit interface? Async serial (aka UART), SPI,  or I2C, or something else?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What RFID module? There's quite a few different types.

And why 'pure' assembly? Can you not use the assembly that the C compiler generates?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And if it is an Arduino Uno, why not use the Arduino IDE and its native C/C++? There are versions of the IDE that work on a Mac, on Linux, and on a PC.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have no idea about all this . I am a beginner. I just want to interface any RFID module . ANY SYGGESTIONS are welcome.

Raj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to learn pure assembly language. I want to write my own functions. C provides inbuilt functions for this. I want to learn all the basics things working behind assembly.

Raj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am compiling all the pure assembly code in ubuntu using 'makefile' in terminal. I want to learn pure assembly. If I learned pure assembly programming then I can easily switch to avr-gcc.

Raj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One does not ‘compile’ assembly code, one ‘assembles’ it using an assembler. So what is the difference with ‘pure’ assembly code vs normal assembly code? Is there such a thing as ‘impure’ assembly??
I think you’d better choose what rfid you use. If i suggested using a rc522 chip, you’ll be writing assembler for the next year.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok , we assembles . fine.

Pure assembly means not programming in C language. Only assembly code .

 

I choose EM-18(RFID reader module).

Raj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That reader has an RS-232 option which is REALLY just a UART. So, you will have serial data. 

 

Though somewhat sketchy, the pin connections, serial settings, and output format are shown here: http://www.nskelectronics.com/em...

 

You will have to receive a series of ASCII characters (12 of them) and decode according to some rules given in the reference above) to get the ID number of the tag. That is all you get. It runs autonomously - that is, IT determines when a tag is present, then IT sends your micro the data string. So, you just collect those 12 characters, extract the ID number, and do what ever you want with that number. There are 10 decimal digits which you will need to display on 10 7-segment digits multiplexed if that is what you want.

 

Actually, its NOT a terribly hard project for a beginner (in C), but starting from the level you are at with assembler makes it maybe 4 or 5 times harder. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what is the difference with ‘pure’ assembly code vs normal assembly code?

Assembly code that has not been defiled by a C programmer of course...... devil

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I personally think assembler is easier than C.  No structure, half a dozen commands.  But don't know how that applies to Arduino as I use the standard IDE.  I haven't seen anyone using assembler on Arduino.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't know where you get "half a dozen". Atmel counts 131 "powerful instructions" on Mega328.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Assembler is technically simpler - each opcode does a very simple operation that is easily explained. That is where the simplicity ends - how to multiply numbers, floating point representation and so on where the apparent complexity is managed by the C compiler. Now, we're seeing people who started using Arduino 'language' and want to use 'pure' C as they mistakenly think it will unlock magic, find that even converting a variable to a string is a challenge. That level of complexity was handled by the Arduino framework. By lowering the barriers for adopting technology, we're hiding the fundamentals. Your comment about assembler having 'no structure' is worrying. For those of us who have worked on large assembler, even C projects know that structure is the key component to managing the complexity. There's plenty of people that say they can program in Assembler - the reality is a skilled programmer can use any language. Programming is somewhat different to writing code. We can see that with Raj - all he is worried about is the 'code', not the method of solving a given programming task. The 'code' is the result of design, not the beginning and end.

I taught myself how to code in machine code when I was young. It took a few more years to learn the design process. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I said "half a dozen," I was not referring to the chip's total number of opcodes, but rather the usual mov, jmp, etc.  Very few of these commands are needed to make a functional program.  I looked through one of my old programs and it was amazing how many lines start with "mov." When I said "no structure," I mean like Basic.  There is no enforced structure.  You could have 1000 lines of code with goto statements scattered about.  I did not say this is the correct way to develop large, complex applications!cheeky

Last Edited: Tue. Nov 14, 2017 - 02:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

barrage_97 wrote:
I personally think assembler is easier than C

Ha Ha - let the language wars begin!!

 

Sure, the available instructions in ASM are simpler than in a HLL - but that's because each one does only a very simple thing.

 

To actually achieve anything ASM means that you have to use huge number of these simple instructions, and you have to manage every tiny detail of memory allocation, register usage, stack usage, etc, etc

 

So, although the individual instructions may be "easy", forming a useful program is extremely laborious - and, thus, error-prone.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

barrage_97 wrote:
I looked through one of my old programs and it was amazing how many lines start with "mov."

 

Is it x86? Because x86 "mov" corresponds to several common AVR instructions like mov, ld, st, ldi etc., so naturally x86 assembly has a lot of movs.

 

@Raj666

 

What OS are you using? Windows? Linux? Mac?

 

You can use the Arduino IDE to learn assembly, by adding .s (pure assembly) or .S (tainted assembly) files to your project.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:
tainted assembly

 

Image result for ooh err missus

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

barrage_97 wrote:

Very few of these commands are needed to make a functional program.

 

Very few C keywords are needed to write a functional C program. I reckon you can write just about any C program with just 10 keywords.

 

 

barrage_97 wrote:

I looked through one of my old programs and it was amazing how many lines start with "mov."

 

I looked through one of my current C programs and was amazed to see how many lines ended with ";".

 

 

barrage_97 wrote:

When I said "no structure," I mean like Basic.  There is no enforced structure.  You could have 1000 lines of code with goto statements scattered about.  I did not say this is the correct way to develop large, complex applications!

 

But you can write unstructured C; there's nothing inherent in the language that enforces a structure any more than assembly does.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

Last Edited: Tue. Nov 14, 2017 - 04:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And out of interest...

 

Quote:

ATmega328P instruction use summary:
.lds  :   0 .lds.l:   0 .sts  :   0 .sts.l:   0 adc   :  40 add   :  45 
adiw  : 138 and   :   2 andi  :  26 asr   :   0 bclr  :   0 bld   :   3 
brbc  :   0 brbs  :   0 brcc  :   2 brcs  :   0 break :   0 breq  : 130 
brge  :  21 brhc  :   0 brhs  :   0 brid  :   0 brie  :   0 brlo  :  24 
brlt  :  28 brmi  :   0 brne  : 247 brpl  :   4 brsh  :  14 brtc  :   2 
brts  :   0 brvc  :   0 brvs  :   0 bset  :   0 bst   :   2 call  : 486 
cbi   :  29 cbr   :   1 clc   :   0 clh   :   0 cli   :   5 cln   :   0 
clr   :  65 cls   :   0 clt   :   3 clv   :   0 clz   :   0 com   :   9 
cp    :  33 cpc   :  49 cpi   : 389 cpse  :   0 dec   :  12 des   :   0 
eor   :   4 fmul  :   0 fmuls :   0 fmulsu:   0 icall :   8 ijmp  :   0 
in    :  12 inc   :   2 jmp   :  28 ld    :  87 ldd   : 218 ldi   :1308 
lds   : 264 lpm   :  11 lsl   :  47 lsr   :   9 mov   : 170 movw  :  70 
mul   :   9 muls  :   0 mulsu :   0 neg   :  13 nop   :   0 or    :   7 
ori   :   6 out   :  39 pop   :   6 push  :   6 rcall :  72 ret   :  63 
reti  :   7 rjmp  : 372 rol   :  45 ror   :  12 sbc   :  19 sbci  :  61 
sbi   :  29 sbic  :   5 sbis  :  12 sbiw  :  43 sbr   :   2 sbrc  :  15 
sbrs  :  21 sec   :   0 seh   :   0 sei   :   3 sen   :   0 ser   :  13 
ses   :   0 set   :   3 sev   :   0 sez   :   0 sleep :   0 spm   :   0 
st    : 338 std   : 139 sts   : 236 sub   :  16 subi  : 127 swap  :   0 
tst   :   7 wdr   :   3 
Instructions used: 73 out of 116 (62.9%

 

...from an application that uses about 60% of a 328's flash.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
 there's nothing inherent in the language that enforces a structure 

But plenty that enables a structure.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As someone who did 15+ years of assembly before I ever went near a C compiler I can possibly understand the desire to learn things from the "bottom up". But the fact I then spent the next 20 years doing C and then 5+ doing C++ is that I learned over the years that the "best" way to implement designs is actually with as high a level language possible. They don't "hide things" because you can always explore the Asm they produce but they don't make "silly mistakes" either so you can get on with designing/implementing easily maintainable logic.

 

Personally I'd get the thing working in C (or even C++) and then work back from there to explore the Asm.

 

As I say nothing is ever really "hidden" or "out of your control" when you use C or C++. You can study things like CRT and if you don't like what they are doing you can easily turn most such things off and implement your own "better" design.

 

The usual analogy is the car one that says if you want to get from NY to LA do you just buy a car and drive? Or do you buy a bit of parts and assemble your own car first? Or do you even buy a steel mill, a rubber processing plant and an aluminium foundry and create your own wheels, panels, frame, engine block and so on before you even try to assemble a kit of parts? Sure you can have fun doing it but it's not going  to make the journey to LA any easier!

 

BTW why are you using a ready made Arduino for the hardware? Why not build your own circuit up from a set of components? Come to that why are you even using an AVR? If you buy something like 40,000 transistors you should be able to make your own! Actually with a bucket of sand and a furnace and you could grow yourself some silicon crystals.

Last Edited: Tue. Nov 14, 2017 - 04:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess there's something to be said for beginners doing a couple of simple exercises in ASM just get an insight into what goes on at the low level - but I really don't see the point in struggling to do a significant project like this entirely in assembler.

 

I think Kartman hit it on the head in #14 with:

Programming is somewhat different to writing code. We can see that with Raj - all he is worried about is the 'code', not the method of solving a given programming task. 

That seems to be the problem with most questions posted here: people are just jumping straight into code without first understanding the problem or having any kind of design for the solution.

 

The skill that is missing is problem-solving - not coding. 

 

See also: http://www.avrfreaks.net/comment...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is going on this??????frown

You all has just confused me.

Anyone just please give me the algorithm to interface RFID EM-18 module.

Give in steps.please.

 

Raj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Check this out. 

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Raj666 wrote:
 give me the algorithm to interface RFID EM-18 module.

Give in steps.please.

 

4 steps - here: http://www.8052.com/forum/read/1...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sir , I know how to interface using Arduino IDE.

I want to interface it in .asm code ie. in assembly language.

 

Raj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have the code in the Arduino IDE that is the algorithm you require.

 

The RFID chip neither knows nor cares what language you write your code in.

 

So take the Arduino code as your specification of what your assembler code must do, and break it down into assembler-level steps.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Raj666 wrote:
Sir , I know how to interface using Arduino IDE. I want to interface it in .asm code ie. in assembly language.
When you build Arduino code it GENERATES Asm code. Why don't you simply study that ?

 

Try to be realistic. No one else is going to attempt something as foolish as trying to interface RFID in Asm so the only examples you are going to be "given" are going to be C or C++ (Arduino) examples. If you REALLY think there is some merit in having that in Asm then either get a C/C++ compiler to convert it from C/C++ to Asm for you and study that or simply sit and look at the sequence and procedures being implemented in the high level source and taking each step of that at a time consider how you would achieve the same in Asm. So if you see something like:

PORTB = 0xA5;

in the C/C++ then you know you need to write:

LDI R24, 0xA5
OUT PORTB, R24

in your own Asm version and so on. After a while you will have done by hand what the C/C++ compiler will have done for you automatically.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Raj666 wrote:

What is going on this??????frown

You all has just confused me.

Anyone just please give me the algorithm to interface RFID EM-18 module.

Give in steps.please.

 

 

Setup:

 1) init display

 2) init usart (9600 baud)

 

loop:

  Do 12 times( read character from usart, save in data array)

 

  Display the 12 bytes of data in array

 

rinse and repeat as needed!

 

 

Jim

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Is it x86? Because x86 "mov" corresponds to several common AVR instructions like mov, ld, st, ldi etc., so naturally x86 assembly has a lot of movs."

 

Yes it is x86.  I hope Raj666 is getting something out of this discussion, because if he insists on using assembler he needs to know the pros and cons of doing that. I should clarify that on Windows XP, I was using Microsoft Assembler.  I use Windows API, and libraries.  To get a fully functioning window on the screen takes around 100 lines of assembly code.  Also memory management is much easier than in the old DOS days.

Last Edited: Wed. Nov 15, 2017 - 12:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

barrage_97 wrote:
I should clarify that on Windows XP, I was using Microsoft Assembler. I use Windows API, and libraries. To get a fully functioning window on the screen takes around 100 lines of assembly code.
Anyone remember GEM? (original competitor to Microsoft Windows from Digital Research). I programmed that using MASM86 because at the time I didn't know/understand enough C. It was about the same - perhaps 100+ lines to make something visible happen.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I remember that it was a thing, but I don't think I ever used it!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Anyone remember GEM?

 

Yep, and I should still have the installation disks somewhere.

 

Back in my TV days we had a large intercom system whose configuration software ran under GEM which meant a dedicated PC to run it on.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

back to the opening question,

 

Raj666 wrote:
 Anyone can provide the appropriate resources to study

That would be the datasheet for the RFID module in question.

 

You should also visit the website of the manufacturer (and distributor) to look for additional support materials.

 

 

I just want to know the basics of interfacing RFID in assembly language

There is nothing specific about RFID to it.

 

The basics of interfacing to anything are the same.

 

It's also not specific to assembly language - the process is the same whatever language you choose:

 

You design what your code needs to do - based on your study of the datasheet, and any other supporting materials - and then you code that in the language of your choice.

 

 

Last Edited: Wed. Nov 15, 2017 - 11:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Funny thing was that back in the late 80's GEM was actually a "much nicer" WIMP environment than Windows which was just making the Windows 2.0 to 3.0 transition at that time. When we first shipped PCs we shipped them with DR-DOS and GEM (DR-DOS (aka "DOS Plus") was also superior to MS-DOS) but corporate clients told us that it had to be MS-DOS and it had to be Windows. So for a while we shipped disks allowing for both to be used but after a while we then just shipped MS-DOS and Windows and fell in line with all the other "sheep". Sad times.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

 Anyone remember GEM? (original competitor to Microsoft Windows from Digital Research). I programmed that using MASM86 because at the time I didn't know/understand enough C. It was about the same - perhaps 100+ lines to make something visible happen.

 

Yes.  GEM was on the Atari ST platform.  Programming the 68000 in assembler was pretty nice.  According to the above links, I believe Raj666 has all the information he needs to get started with his project.  He probably doesn't want to hear about me using Devpac 68000.