Electronics > Beginners
ASM to Arduino
<< < (4/5) > >>
fsr:
You're welcome.
Makes sense to have the PICs, then you can just program them easily and use them with the original project.
westfw:

--- Quote ---Arduino IDE is not happy with the ASM code.
--- End quote ---
It's not "Arduino code", it's an "Atmel Studio" "Project", written for a bare AVR chip.
That means:
* the .ASM files are written for the Atmel Assembler.
* The won't get compiled from the Arduino IDE, which only knows about the Gnu Assembler.
* If you somehow compiled them with the Atmel Assembler, they still wouldn't be linkable into an Arduino "sketch", because the Atmel Assembler doesn't produce linkable object files.
* Your best bet is to build the project with Studio, and upload it to your Arduino via the bootloader.
* (actually, the idea of converting it all to inline ASM isn't awful, since it's quite short.  You'll need to mess with the options for handling symbols in inline ASM, though.  And don't use symbols that are already defined ("loop", "init"))h
* Except that if it's capable of dividing 10MHz, it's probably expecting the "input frequency" on the clock pin, which is not compatible with Arduino hardware (that already has a 16MHz resonator there.)
--- Quote ---https://ucexperiment.wordpress.com/2016/03/04/arduino-inline-assembly-tutorial-1/
--- End quote ---
inline assembly isn't the only way, nor even the best way, to include ASM in an Arduino sketch.  As of recent versions (not THAT recent), it will happily accept .S files in the sketch directory.)
westfw:
Hmm.  Your attempt to produced inline ASM was pretty credible.
I already mentioned symbol conflicts...

--- Quote ---#include <m32def.inc>
--- End quote ---
Get rid of that; it's avr assembler, and the equivalent is already included.
--- Quote ---        "OUT        DDRA,R16 \n"
--- End quote ---
But symbols need to be referenced "specially."  See https://www.nongnu.org/avr-libc/user-manual/inline_asm.html
(The tutorial you found wasn't very good.)
--- Quote ---"WLP1:   DEC      \n"
--- End quote ---
There was a type or two - missing argument for DEC, here.  And I think one other...
--- Quote ---My favorite error is the "garbage at the end of line"
--- End quote ---
And THAT, of course, is the gnu assembler's way of telling you that "08" is not a valid octal number.  Obviously.It's a C think that nn is decimal, 0nn is octal, and 0xnn is hex...
Try this version:
--- Code: ---#include <avr/io.h>

void setup(){
asm (
        "LDI    R16,0xFF \n"
        "OUT    %0,R16 \n"
        "CLR    R15 \n"
        "CLR    R14 \n"
        "CLR    R13 \n"
        "CLR    R12 \n"
        "CLR    R11 \n"
        "CLR    R10 \n"
        "CLR    R9 \n"
        "CLR    R8 \n"

"pploop: \n"
        "LDI    R16,0x0A \n"   
        "INC    R15 \n"
        "CP     R15,R16 \n"
        "BRNE   nd1 \n"
        "CLR    R15 \n"
"nd1:   BRNE    nd1w \n"
        "INC    R14 \n"
"nd1w:  CP      R14,R16 \n"
        "BRNE   nd2 \n"
        "CLR    R14 \n"
"nd2:   BRNE    nd2w \n"
        "INC    R13 \n"
"nd2w:  CP      R13,R16 \n"
        "BRNE   nd3 \n"
        "CLR    R13 \n"
"nd3:   BRNE    nd3w \n"
        "INC    R12 \n"
"nd3w:  CP      R12,R16 \n"
        "BRNE   nd4 \n"
        "CLR    R12 \n"
"nd4:   BRNE    nd4w \n"
        "INC    R11 \n"
"nd4w:  CP      R11,R16 \n"
        "BRNE   nd5 \n"
        "CLR    R11 \n"
"nd5:   BRNE    nd5w \n"
        "INC    R10 \n"
"nd5w:  CP      R10,R16 \n"
        "BRNE   nd6 \n"
        "CLR    R10 \n"
"nd6:   BRNE    nd6w \n"
        "INC    R9 \n"
"nd6w:  CP      R9,R16 \n"
        "BRNE   cready \n"
        "CLR    R9 \n"
"cready: CLT \n"
        "BLD    R8,0 \n"
        "OUT    %1,R8 \n"
        "LDI    R17,8 \n"
"WLP0:  DEC     R17 \n"
        "BRNE   WLP0 \n"
        "CLR    R8 \n"
        "LDI    R16,0x05 \n"
        "SET \n"
        "BLD    R8,0 \n"
        "CP     R15,R16 \n"
        "BRCS   d2 \n"
        "BLD    R8,1 \n"
"d2:    CP      R14,R16 \n"
        "BRCS   d3 \n"
        "BLD    R8,2 \n"
"d3:    CP      R13,R16 \n"
        "BRCS   d4 \n"
        "BLD    R8,3 \n"
"d4:    CP      R12,R16 \n"
        "BRCS   d5 \n"
        "BLD    R8,4 \n"
"d5:    CP      R11,R16 \n"
        "BRCS   d6 \n"
        "BLD    R8,5 \n"
"d6:    CP      R10,R16 \n"
        "BRCS   d7 \n"
        "BLD    R8,6 \n"
"d7:    CP      R9,R16 \n"
        "BRCS   ok \n"
        "BLD    R8,7 \n"
"ok:    OUT     %1,R8 \n"
        "LDI     R17,3 \n"
"WLP1:   DEC     R17 \n"
        "BRNE    WLP1 \n"
        "NOP \n"
        "RJMP  pploop\n"
        :: "I"(_SFR_IO_ADDR(DDRD)), "I"(_SFR_IO_ADDR(PORTD))
);
}

--- End code ---
westfw:
(change PORTD and DDRD back to PORTA and DDRA for your m32...)
metrologist:
Thanks for looking at this and the code. I added void loop(){} and your code compiled. So now we just need the 10M coax to the clock (there are two clock pins?) and we can find the divided signals on other pins? I do have a handful of bootloaded bare 328p chips.
Navigation
Message Index
Next page
Previous page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod