this is a brutally simple interface for a spi pin 1 - chip select cr pin 3 - clock cr pin 5 - mosi cr pin 17 - miso cr /spi call first. main loop .
pauses for an effective rate of 2mhz cr -ckwait asserts the clock line low for 2mhz cr cs asserts the chip select line high cr -cs asserts the chip select line low cr |
850 list
todd's simple spi code cr 8 node 0 org cr /spi @ push ex . /spi ;
02 4A for unext ; approx. 2mhz cr -ckwait 05 2B !b ckwait ;
07 io b! -ckwait ;
0A 29 !b ;
0C if drop 10 then 2F or !b ckwait -ckwa
13 b- 80 7 for over over and spiw1 2/ ne
1A -b @b . -if drop - 2* - ; then drop 2
1E -b 0 7 for 0 spiw1 spir1 next 2/ ; cr 26 |
|
nxp pcf2123 calendar clock module.
initializes the pcf2123 clock cr rdt reads date and time
sets data and time port the cr |
852 list
7 node 0 org cr /cs 00 left a! @p .. cs ! ;
04 @p .. -cs ! ;
07 d- @p .. @p .. ! ! ;
0A -d @p .. !p .. ! @ ;
0D put @p .. spiw8 ! ;
11 @p .. spir8 ! get ;
14 @p .. /spi ! /cs 10 spiw 58 spiw c
1C -smhwdmy /cs 92 spiw spir spir spir spi
27 ymdwhms- /cs 12 spiw spiw spiw spiw spi
32 12 11 10 9 8 7 6 sdt ; cr 3C |
Friday, February 17, 2012
arrayForth notes #6 - Improved PCF2123 SPI Code
There were a lot of errors in the note #4 listing. I made the post mainly because I was excited to see commands fly between the PCF2123 and GA144 as viewed by a logic analyzer (even though spir8 didn't really work correctly).
So, here is where I clean up the code, refactor it a bit and offer something a little more functional.
I could go on for pages the rationale I had behind why this code lives in Node 7 and 8 and how I hooked up the chip. But, that is for another time. I hate having broken code posted to my blog, so this post is mainly a means to offer something that works. BTW, this runs on the eval board target chip.
It still has some inefficiencies (compared to the GreenArray supplied SPI code), but by doing this myself (essentially a "clean room" implementation), I got to learn a lot more about how to code the GA144.
Subscribe to:
Post Comments (Atom)
see
ReplyDeleteget:
@p .. !p .. ! @ ;
you can save 1 word if you write
instead
get:
@p ! @ ; !p ..
so its reordered but does the same
Thanks. Every word is precious ;-)
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete