[En-Nut-Discussion] TWI and Lua problem

uprinz uprinz2 at netscape.net
Mon Apr 11 18:24:20 CEST 2011

Andre Riesberg wrote:
> Bernd Walter schrieb:
>> On Sun, Apr 10, 2011 at 11:20:49PM +0200, Ulrich Prinz wrote:
> Hi all,
> the TwMasterRegWrite and TwMasterRegRead are the better functions.
> TwMasterRegWrite can send up to 5 bytes, one address, up to three more 
> address (or data) bytes and another data byte. This is done without any 
> "byte sending" interrupt.
> The function TwMasterTransact works reliable for only one data byte.
> If we want to send more then 5 bytes, we have to write our own function 
> without interrupts.
> The automatic stop bit very bad.
> But I hope there is a solution for this issue!
> Greetings
> André
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion

Just add the writing of the first byte to the TWDR register in the code. 
at91_twi.c is your friend around line 370 if I remember corretly.

        /* Set TWI Internal Address Register */
        outr(TWI_IADRR, iadr);
        /* Set the TWI Master Mode Register */
        outr(TWI_MMR, ((unsigned int) sla << TWI_DADR_LSB) | (((unsigned
int) iadrlen & 3) << 8));
        outb(TWI_THR, tw_mm_buf[0]);
        outr(TWI_IER, TWI_TXRDY);

My version of this code seems to directly set the first byte into TWI_THR
before enabling the interrupts.
But as you said, the code seems to work for up to five bytes. Let me guess:
You write 1 byte chip address, 2 bytes in-chip address and 2 byte of data,
where after the first data it again fails.

What I wonder about is, that the interrupt is coming so late that we cannot
even put a single byte into the THR register early enough. So either
interrupt-handling or buffer management is so slow, that it interrupts the
I2C communication.

Ok, in the stm implementation I think I use real buffer pointers, while in
the AT91 code there are indexes used. I need to check what assembler code
differences result of using buffer[i] instead of *bufptr++;

On the other hand, this is one of the shortest I2C interrupt handler I ever
wrote :)


Best regards
View this message in context: http://old.nabble.com/TWI-and-Lua-problem-tp31362584p31371770.html
Sent from the MicroControllers - Ethernut mailing list archive at Nabble.com.

More information about the En-Nut-Discussion mailing list