Tested with AT91R40008 only. Other ARMs or AVR may not work.
* * $Log: twbbif.c,v $ * Revision 1.6 2006/10/08 16:48:09 haraldkipp * Documentation fixed * * Revision 1.5 2006/06/28 17:10:35 haraldkipp * Include more general header file for ARM. * * Revision 1.4 2006/05/25 09:30:23 haraldkipp * Compiles for AVR. Still not tested, though. * * Revision 1.3 2006/04/07 12:50:20 haraldkipp * Added additional delays in TwAck. * Clock and data forced to high before switching to input gives better * waveforms. * Additional delay added to set clock to 50% duty cycle. The PCF8563 * seems to fail, if the clock's high time is much longer than the low time. * * Revision 1.2 2006/01/23 17:32:35 haraldkipp * Automatic initialization added. * * Revision 1.1 2005/10/24 10:21:57 haraldkipp * Initial check in. * * *
#include <cfg/os.h>
#include <dev/twif.h>
Defines | |
#define | TWI_DELAY 8 |
Functions | |
int | TwInit (u_char sla) |
Initialize TWI interface. | |
int | TwIOCtl (int req, void *conf) |
Perform TWI control functions. | |
int | TwMasterError (void) |
Get last master mode error. | |
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 | TwSlaveError (void) |
Get last slave 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 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.
sla | Slave address, must be specified as a 7-bit address, always lower than 128. |
int TwIOCtl | ( | int | req, | |
void * | conf | |||
) |
Perform TWI control functions.
Not implemented in the bit banging version.
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. |
int TwMasterError | ( | void | ) |
Get last master mode error.
You may call this function to determine the specific cause of an error after TwMasterTransact() failed.
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.
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. |
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.
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().
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. |
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.
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. |