From: Erich W. <ew....@na...> - 2012-06-03 08:39:55
|
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 |