[En-Nut-Discussion] TWI and Ethernut

Ole Reinhardt ole.reinhardt at embedded-it.de
Fri Jan 25 09:31:36 CET 2008


Hello

> Has anyone 
> [...]
> example code of using TWI?

Using TWI with avr is quite simple. Everything you need you'll find in 
/nut/include/dev/twif.h. Always think about using a mutex in a multi
threaded application to avoid ressource conflicts.

Just a short example:

char PCF8575_OutW(u_char sub_addr, u_char* data)
{
    u_char addr;
    addr = PCF8575_ADR_BASE | (sub_addr & 0x07);
    if (TwMasterTransact(addr, data, 2, NULL, 0, I2C_TIMEOUT) == -1)
        return -1; 
    else 
        return 0;
}

char PCF8575_InW(u_char sub_addr, u_char* data)
{
    u_char addr;
    addr = PCF8575_ADR_BASE | (sub_addr & 0x07);
    if (TwMasterTransact(addr, NULL, 0, data, 2, I2C_TIMEOUT) == -1)
        return -1; 
    else 
        return 0;
}

Bye,

Ole Reinhardt


-- 
 _____________________________________________________________
|                                                             |
| Embedded-IT          Hard- und Softwarelösungen             |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt at embedded-it.de |
| Germany              Web:         http://www.embedded-it.de |
|                      UstID / VAT:       DE198944716         |
|_____________________________________________________________|




More information about the En-Nut-Discussion mailing list