For reference here are two words I use to communicate with an external DAC on an Arduino R3. This is my first forage into inlining conditional AVR-assembly in Forth. PORTB is set all output elsewhere.
Cheers
/Micke
(Update: sorry about the lack of indentation. The editor apparently does not acknowledge spaces...)
And an ever bigger thanks for the Flashforth! It really is a clever environment. I'm having a ball with it. Currently I am investigating if signal processing can be done with the ATmega's meagre speed. I use ff for logical structure and ease of programming and code critical words in assembler. If I get any results I will post them here too.
/Micke (SM5JAB...)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all!
For reference here are two words I use to communicate with an external DAC on an Arduino R3. This is my first forage into inlining conditional AVR-assembly in Forth. PORTB is set all output elsewhere.
Cheers
/Micke
(Update: sorry about the lack of indentation. The editor apparently does not acknowledge spaces...)
\ 8-bit DAC routines
-mcp48x2
marker -mcp48x2
$4c constant SPCR
$4d constant SPSR
$4e constant SPDR
$50 SPCR c!
$01 SPSR c! \ double speed fosc/2
;
[ R24 swap, ] \ 4 lshift
[ R25 R24 mov, ]
[ R25 $0f andi, ]
[ R25 $10 ori, ] \ $1000 or
[ PORTB 2 cbi, ] \ SS on device low
[ SPDR R25 sts, ] \ Send 1st byte
[ begin, ] \ wait for SPIF, SPDR bit7
[ R25 SPSR lds, ]
[ R25 $80 andi, ]
[ mi, until, ]
[ SPDR R24 sts, ] \ Send 2nd byte
[ begin, ] \ wait for SPIF
[ R24 SPSR lds, ]
[ R24 $80 andi, ]
[ mi, until, ]
[ R24 Y+ ld, ] \ drop
[ R25 Y+ ld, ]
[ PORTB 2 sbi, ] \ SS on device high
;
Last edit: jabcam 2017-03-15
You can format the code in a code block with \</> or ctrl-alt-C /Micke
Last edit: Mikael Nordman 2017-03-16
Thanks for the tip!
And an ever bigger thanks for the Flashforth! It really is a clever environment. I'm having a ball with it. Currently I am investigating if signal processing can be done with the ATmega's meagre speed. I use ff for logical structure and ease of programming and code critical words in assembler. If I get any results I will post them here too.
/Micke (SM5JAB...)
Thanks for the code.
There has been requests for Atmega assembler examples, and your code is really good.
Keep them coming !
fe value isy
ff to isy
:-)
Last edit: Mikael Nordman 2017-03-16