Hi Jan,
On 06/02/2012 07:33 PM, Jan Kromhout wrote:
> Dear Erich,
> I have done what you wrote, seems to work.
Very good!
> But when I look to te code of twi.frt I see
> some strange thing, or missing sommething.
> When I look into the code never is sending
> the address in twi.start \ send start condition
> : twi.start ( -- )
> [ 1 7 lshift
> 1 5 lshift or
> 1 2 lshift or ] literal
> TWCR c!
> twi.wait
> ;
>
> Where should I put the address?
The address is just the first byte to be transfered.
I use the following functions to send/receive n Byte to/from
some address. Feel free to recycle them:
\ send n bytes to addr
: >i2c ( x1 .. xN.msB N addr -- )
twi.start
twi.tx \ uses addr
0 do \ uses N
twi.tx \ uses xN .. x1
loop
twi.stop
;
: <i2c ( N addr -- xN.msB .. x1 )
twi.start
1+ twi.tx \ uses addr
1- dup 0 > if
0 do twi.rx loop
else
drop
then
twi.rxn
twi.stop
;
As you can see, the first call to twi.tx sends the addr.
If you have not downloaded the datasheet of your controller
from atmel.com, please do so. I know, these datasheets are
rather intimidating at first, however, they do include a lot
of information, e.g. how to set the bits in TWCR and their
meaning. I strongly suggest to consult the datasheet often.
You will learn to read it. And amforth will let you access
the registers and bits easily.
Cheers,
Erich
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
[email protected]
https://lists.sourceforge.net/lists/listinfo/amforth-devel