twif.h File Reference

Go to the source code of this file.

Defines

#define TWI_SETSPEED   0x0401
 Set transfer speed.
#define TWI_GETSPEED   0x0402
 Query transfer speed.
#define TWI_SETSLAVEADDRESS   0x0403
 Set local slave address.
#define TWI_GETSLAVEADDRESS   0x0404
 Query local slave address.
#define TWI_SETSTATUS   0x0409
 Set status.
#define TWI_GETSTATUS   0x040a
 Query status.
#define TWERR_OK   0
 No error occured.
#define TWERR_TIMEOUT   1
 Interface timeout.
#define TWERR_BUS   2
 Bus error.
#define TWERR_IF_LOCKED   3
 Interface locked.
#define TWERR_SLA_NACK   4
 No slave response.
#define TWERR_DATA_NACK   5
 Data not acknowledged.
#define TWSLA_MIN   17
 Lowest slave address. Addresses below are reserved for special purposes.
#define TWSLA_MAX   79
 Lowest slave address. Addresses above are reserved for special purposes.
#define TWSLA_BCAST   0
 Broadcast slave address.
#define TWSLA_HOST   16
 Host slave address.
#define TWSLA_DEFAULT   193
 Default slave address.

Functions

int TwInit (u_char sla)
 Initialize TWI interface.
int TwIOCtl (int req, void *conf)
 Perform TWI control functions.
int TwMasterTransact (u_char sla, CONST void *txdata, u_short txlen, void *rxdata, u_short rxsiz, u_long tmo)
 Transmit and/or receive data as a master.
int TwMasterError (void)
 Get last master mode error.
int TwSlaveListen (u_char *sla, void *rxdata, u_short rxsiz, u_long tmo)
 Listen for incoming data from a master.
int TwSlaveRespond (void *txdata, u_short txlen, u_long tmo)
 Send response to a master.
int TwSlaveError (void)
 Get last slave mode error.


Define Documentation

#define TWI_SETSPEED   0x0401

Set transfer speed.

Definition at line 51 of file twif.h.

Referenced by TwInit(), and TwIOCtl().

#define TWI_GETSPEED   0x0402

Query transfer speed.

Definition at line 52 of file twif.h.

Referenced by TwIOCtl().

#define TWI_SETSLAVEADDRESS   0x0403

Set local slave address.

Definition at line 53 of file twif.h.

Referenced by TwIOCtl().

#define TWI_GETSLAVEADDRESS   0x0404

Query local slave address.

Definition at line 54 of file twif.h.

Referenced by TwIOCtl().

#define TWI_SETSTATUS   0x0409

Set status.

Definition at line 55 of file twif.h.

Referenced by TwIOCtl().

#define TWI_GETSTATUS   0x040a

Query status.

Definition at line 56 of file twif.h.

Referenced by TwIOCtl().

#define TWERR_OK   0

No error occured.

Definition at line 59 of file twif.h.

#define TWERR_TIMEOUT   1

Interface timeout.

Definition at line 60 of file twif.h.

Referenced by TwMasterTransact(), TwSlaveListen(), and TwSlaveRespond().

#define TWERR_BUS   2

Bus error.

Definition at line 61 of file twif.h.

Referenced by TwSlaveError().

#define TWERR_IF_LOCKED   3

Interface locked.

Definition at line 62 of file twif.h.

Referenced by TwMasterTransact().

#define TWERR_SLA_NACK   4

No slave response.

Definition at line 63 of file twif.h.

Referenced by TwMasterTransact().

#define TWERR_DATA_NACK   5

Data not acknowledged.

Definition at line 64 of file twif.h.

#define TWSLA_MIN   17

Lowest slave address. Addresses below are reserved for special purposes.

Definition at line 67 of file twif.h.

#define TWSLA_MAX   79

Lowest slave address. Addresses above are reserved for special purposes.

Definition at line 71 of file twif.h.

#define TWSLA_BCAST   0

Broadcast slave address.

Definition at line 75 of file twif.h.

#define TWSLA_HOST   16

Host slave address.

Definition at line 76 of file twif.h.

#define TWSLA_DEFAULT   193

Default slave address.

Definition at line 77 of file twif.h.


Function Documentation

int TwInit ( u_char  sla  ) 

Initialize TWI interface.

The specified slave address is used only, if the local system is running as a slave. Anyway, care must be taken that it doesn't conflict with another connected device.

Parameters:
sla Slave address, must be specified as a 7-bit address, always lower than 128.
Returns:
Always 0.
Note:
Slave mode is not implemented in the bit banging version. Thus the given slave address is ignored.

Definition at line 899 of file twif.c.

Referenced by DS1307Init(), PcfRtcInit(), TwMasterTransact(), and X12Init().

int TwIOCtl ( int  req,
void *  conf 
)

Perform TWI control functions.

Not implemented in the bit banging version.

Parameters:
req Requested control function.
conf Points to a buffer that contains any data required for the given control function or receives data from that function.
Returns:
Always 0.

Definition at line 827 of file twif.c.

Referenced by TwInit().

int TwMasterTransact ( u_char  sla,
CONST void *  txdata,
u_short  txlen,
void *  rxdata,
u_short  rxsiz,
u_long  tmo 
)

Transmit and/or receive data as a master.

The two-wire serial interface must have been initialized by calling TwInit() before this function can be used.

Parameters:
sla Slave address of the destination. This slave address must be specified as a 7-bit address. For example, the PCF8574A may be configured to slave addresses from 0x38 to 0x3F.
txdata Points to the data to transmit. Ignored, if the number of data bytes to transmit is zero.
txlen Number of data bytes to transmit. If zero, then the interface will not send any data to the slave device and will directly enter the master receive mode.
rxdata Points to a buffer, where the received data will be stored. Ignored, if the maximum number of bytes to receive is zero.
rxsiz Maximum number of bytes to receive. Set to zero, if no bytes are expected from the slave device.
tmo Timeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE.
Returns:
The number of bytes received, -1 in case of an error or timeout.
Note:
Timeout is not used in the bit banging version.

Definition at line 532 of file twif.c.

References TWERR_SLA_NACK, and TwInit().

Referenced by Cy2239xGetDivider(), Cy2239xGetFreq(), Cy2239xGetPll(), Cy2239xPllEnable(), Cy2239xPllGetFreq(), Cy2239xPllSetFreq(), Cy2239xSetDivider(), Cy2239xSetPll(), DS1307RamWrite(), DS1307RtcReadRegs(), DS1307RtcWrite(), PcfRtcReadRegs(), PcfRtcWrite(), X12EepromRead(), X12EepromWrite(), X12RtcReadRegs(), and X12RtcWrite().

int TwMasterError ( void   ) 

Get last master mode error.

You may call this function to determine the specific cause of an error after TwMasterTransact() failed.

Returns:
Error code or 0 if no error occurred.

Definition at line 617 of file twif.c.

int TwSlaveListen ( u_char sla,
void *  rxdata,
u_short  rxsiz,
u_long  tmo 
)

Listen for incoming data from a master.

If this function returns without error, the bus is blocked. The caller must immediately process the request and return a response by calling TwSlaveRespond().

Note:
Slave mode is not implemented in the bit banging version. Thus the function always returns -1.
Parameters:
sla Points to a byte variable, which receives the slave address sent by the master. This can be used by the caller to determine whether the the interface has been addressed by a general call or its individual address.
rxdata Points to a data buffer where the received data bytes are stored.
rxsiz Specifies the maximum number of data bytes to receive.
tmo Timeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE.
Returns:
The number of bytes received, -1 in case of an error or timeout.

Definition at line 650 of file twif.c.

int TwSlaveRespond ( void *  txdata,
u_short  txlen,
u_long  tmo 
)

Send response to a master.

This function must be called as soon as possible after TwSlaveListen() returned successfully, even if no data needs to be returned. Not doing so will completely block the bus.

Note:
Slave mode is not implemented in the bit banging version. Thus the function always returns -1.
Parameters:
txdata Points to the data to transmit. Ignored, if the number of bytes to transmit is zero.
txlen Number of data bytes to transmit.
tmo Timeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE.
Returns:
The number of bytes transmitted, -1 in case of an error or timeout.

Definition at line 724 of file twif.c.

int TwSlaveError ( void   ) 

Get last slave mode error.

You may call this function to determine the specific cause of an error after TwSlaveListen() or TwSlaveRespond() failed.

Returns:
Error code or 0 if no error occurred.
Note:
Slave mode is not implemented in the bit banging version. Thus the function always returns TWERR_BUS.

Definition at line 799 of file twif.c.

References TWERR_BUS.


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/