|
|
|
Bean
SW_I2C
|
SW emulated I2C using two I/O pins.
Methods are user callable functions/subroutines that are means of controlling the bean functions.
|
Methods:
-
Enable
- This method enables the I2C interface for send and receive operations. This method is always selected if the Enabled in init. code property value is "no".
ANSIC prototype: byte Enable(void)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
Disable
- This method disables the I2C interface for send and receive operations.
ANSIC prototype: byte Disable(void)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
EnableEvent
- This method enables the events.
ANSIC prototype: byte EnableEvent(void)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
DisableEvent
- This method disables the events.
ANSIC prototype: byte DisableEvent(void)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
SendChar
- When working as a MASTER, this method writes 7 bits of slave address plus R/W bit = 0 to the I2C bus and then writes one character (byte) to the bus. The slave address must be specified before by the "SelectSlave" method or in the bean initialization section of Slave address init property. When working as the SLAVE, this method writes one character (byte) to the bus. If the ERR_NOTAVAIL error code returned, the char is successfully sent to master but the master device responds by an acknowledgement instead of no acknowledgement at the end of transfer. OnError event is called in this case.
ANSIC prototype: byte SendChar(byte Chr)
- Chr:byte - Character to send
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode ERR_BUSY - The slave device is busy, it does not respond by the acknowledgement (MASTER mode only) ERR_NOTAVAIL - The master device sends acknowledgement instead of no acknowledgement after the last byte transfer (SLAVE mode only) ERR_DISABLED - Device is disabled ERR_BUSOFF - Clock timeout elapsed (SLAVE mode only)
-
RecvChar
- When working as a MASTER, this method writes 7 bits of slave address plus R/W bit = 1 to the I2C bus and then reads one character (byte) from the bus. The slave address must be specified before by the "SelectSlave" method or in the bean initialization section of Slave address init property. When working as a SLAVE, this method reads one character (byte) from the bus.
ANSIC prototype: byte RecvChar(byte *Chr)
- Chr: Pointer to byte - Pointer to received character
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode ERR_BUSY - The slave device is busy, it does not respond by the acknowledgement (MASTER mode only) ERR_DISABLED - Device is disabled ERR_BUSOFF - Clock timeout elapsed (SLAVE mode only)
-
SendBlock
- When working as a MASTER, this method writes 7 bits of slave address plus R/W bit = 0 to the I2C bus and then writes the block of characters to the bus. If the bean is disabled (by the "Disable" method or initialization), the block is moved to the output buffer if the Output buffer size property is different from zero. The content of the output buffer is sent immediately with the stop condition at the end when the bean is enabled by the "Enable" method. After the output buffer transmission, the whole output buffer is cleared. The slave address must be specified before by the "SelectSlave" method or in bean initialization section of Slave address init property. When working as a SLAVE, this method writes block of characters to the bus. If the ERR_NOTAVAIL error code is returned, the whole block is successfully sent to a master but the master device responds by an acknowledgement instead of no acknowledgment sent at the end of the last block byte transfer. OnError event is called in this case.
ANSIC prototype: byte SendBlock(void* Ptr,word Siz,word *Snt)
- Ptr:void* - A pointer to the block of data to send
- Siz:word - The size of the block
- Snt: Pointer to word - A pointer to the number of data that are sent (copied to buffer)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode ERR_BUSY - The slave device is busy, it does not respond by the acknowledgement (MASTER mode only) ERR_TXFULL - Output buffer is full (MASTER mode only) ERR_NOTAVAIL - The master device sends acknowledgement instead of no acknowledgement after the last byte transfer (SLAVE mode only) ERR_DISABLED - Device is disabled ERR_BUSOFF - Clock timeout elapsed (SLAVE mode only)
-
RecvBlock
- When working as a MASTER, this method writes 7 bits of slave address plus R/W bit = 1 to the I2C bus and then reads the block of characters from the bus. The slave address must be specified before by the "SelectSlave" method or in bean initialization section of Slave address init property. When working as a SLAVE, this method reads the block of characters from the bus.
ANSIC prototype: byte RecvBlock(void* Ptr,word Siz,word *Rcv)
- Ptr:void* - A pointer to the block space for received data
- Siz:word - The size of the block
- Rcv: Pointer to word - A pointer to the number of actually received data
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode ERR_BUSY - The slave device is busy, it does not respond by the acknowledgement (MASTER mode only) ERR_DISABLED - Device is disabled ERR_BUSOFF - Clock timeout elapsed (SLAVE mode only)
-
SendStop
- When working as a MASTER, if the Automatic stop condition property value is 'no', this method sends a valid stop condition to the serial data line of the I2C bus to terminate the communication on the bus after using send methods. When the Automatic stop condition property value is 'yes' or the bean is in a SLAVE mode, this method is not provided.
ANSIC prototype: byte SendStop(void)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode ERR_DISABLED - Device is disabled
-
CheckBus
- When working as a SLAVE, this method checks the I2C bus for a valid start condition of communication. The time of bus checking depends on Clock timeout property value. This method should be called repeatedly in order to capture a valid start condition. If a start condition occurs, the method reads the first byte after the start condition and compares its upper 7 bits with the bean self slave address, which is specified in Slave address property. When the bean is addressed, the method sets the acknowledgement to the bus and returns the master desired operation status (RDST - read status, WRST - write status), otherwise it returns no communication status (NCST - bean is not addressed or no start condition detected). If the bean is addressed, it has to immediately call the appropriate method ('send' method if RDST, 'recv' if WRST) in order to successfully make the desired communication. If the start condition does not occur, the method returns no communication status (NCST - bean is not addressed or no start condition detected). This method is not provided for the MASTER mode and is always selected for the SLAVE mode.
ANSIC prototype: byte CheckBus(byte *Stat)
- Stat: Pointer to byte - A pointer to communication status (RDST, WRST, NCST)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode ERR_DISABLED - Device is disabled ERR_BUSOFF - Clock timeout elapsed when receiving first byte (SLAVE mode only)
-
ClearTxBuf
- When working as a MASTER, this method clears all characters in the output buffer. If the Output buffer size property is equal to zero or the bean is in the SLAVE mode, the method is not provided.
ANSIC prototype: byte ClearTxBuf(void)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
CharsInTxBuf
- When working as a MASTER, this method returns the number of characters in the output buffer. If the Output buffer size property is equal to zero or the bean is in the SLAVE mode, the method is not provided.
[deprecated method]
ANSIC prototype: byte CharsInTxBuf(word *Chr)
- Chr: Pointer to word - Pointer to number of characters in output buffer
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
GetCharsInTxBuf
- When working as a MASTER, this method returns the number of characters in the output buffer. If the Output buffer size property is equal to zero or the bean is in the SLAVE mode, the method is not provided.
ANSIC prototype: word GetCharsInTxBuf(void)
- Return value:word - Number of characters in the output buffer.
-
SelectSlave
- When working as a MASTER, this method selects a new slave for communication by its slave address value. Any send or receive method are directed to or from the selected device, until a new slave device is selected by this method. If the selected slave uses 10-bit slave addressing, as the parameter 7 bits must be passed, which involves 10-bit addressing (11110XX), including two MSBs of slave address (XX). The second byte of the 10-bit slave address must be sent to the slave as a general character of send methods. This method is not provided for the SLAVE mode.
ANSIC prototype: byte SelectSlave(byte Slv)
- Slv:byte - Slave address value
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode ERR_DISABLED - Device is disabled
-
GetSelected
- When working as a MASTER, this method returns the identification address value of the slave, which is currently selected for communication with the master. If the current slave uses 10-bit slave addressing, the method returns the first 7 bits only, which involves 10-bit addressing (11110XX), including two MSBs of the slave address (XX). This method is not able to return the rest value of 10-bit slave address. The method is not provided for the SLAVE mode.
ANSIC prototype: byte GetSelected(byte *Slv)
- Slv: Pointer to byte - A pointer to the current selected slave address value
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
Note: Some methods can be implemented as macros.
|
|
|
Processor ExpertTM and Embedded BeansTM are registered trademarks of UNIS, Ltd.
©1997-2005, UNIS, Ltd.
|
|
|