|
|
|
Bean
InternalI2C
|
Internal I2C Communication Interface
Methods are user callable functions/subroutines that are means of controlling the bean functions.
|
Methods:
-
Enable
- Enables I2C bean. Events may be generated ("DisableEvent"/"EnableEvent").
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
- Disables I2C bean. No events will be generated.
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
- Enables the events.
This method is enabled only if any event is generated.
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
- Disables the events.
This method is enabled only if any event is generated.
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, "Slave address init" property. If interrupt service is enabled and the method returns ERR_OK, it doesn't mean that transmission was successful. The state of transmission is obtainable from (OnTransmitData, OnError or OnArbitLost) events.
When working as a SLAVE, this method writes a character to the internal output slave buffer and, after the master starts the communication, to the I2C bus. If no character is ready for a transmission (internal output slave buffer is empty), the Empty character will be sent (see "Empty character" property).
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_DISABLED - Device is disabled ERR_BUSY - The slave device is busy, it does not respond by an acknowledge (only in master mode and when interrupt service is disabled) ERR_BUSOFF - Clock timeout elapsed or device cannot transmit data
ERR_TXFULL - Transmitter is full (slave mode only) ERR_ARBITR - Arbitration lost (only when interrupt service is disabled)
-
RecvChar
- When working as a MASTER, this method writes 7 bits of slave address plus R/W bit = 1 to the I2C bus, then reads one character (byte) from the bus and then sends the stop condition. The slave address must be specified before, by the "SelectSlave" method or in bean initialization section, property "Slave address init". If interrupt service is enabled and the method returns ERR_OK, it doesn't mean that transmission was finished successfully. The state of transmission must be tested by means of events (OnReceiveData, OnError or OnArbitLost). In case of successful transmission, received data is ready after OnReceiveData event is called.
When working as a SLAVE, this method reads a character from the input slave buffer.
ANSIC prototype: byte RecvChar(byte *Chr)
- Chr: Pointer to byte - 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_DISABLED - Device is disabled ERR_BUSY - The slave device is busy, it does not respond by the acknowledge (only in master mode and when interrupt service is disabled) ERR_BUSOFF - Clock timeout elapsed or device cannot receive data ERR_RXEMPTY - No data in receiver (slave mode only) ERR_OVERRUN - Overrun error was detected from the last character or block received (slave mode only) ERR_ARBITR - Arbitration lost (only when interrupt service is disabled) ERR_NOTAVAIL - Method is not available in current mode - see generated code comment
-
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. The slave address must be specified before, by the "SelectSlave" method or in bean initialization section, "Slave address init" property. If interrupt service is enabled and the method returns ERR_OK, it doesn't mean that transmission was successful. The state of transmission is obtainable from events (OnTransmitData, OnError or OnArbitLost). The buffer passed as a parameter may not be changed until is transmitted (OnTransmitData).
When working as a SLAVE, this method writes a block of characters to the internal output slave buffer and then, after the master starts the communication, to the I2C bus. If no character is ready for a transmission (internal output slave buffer is empty), the "Empty character" will be sent (see "Empty character" property).
ANSIC prototype: byte SendBlock(void* Ptr,word Siz,word *Snt)
- Ptr:void* - Pointer to the block of data to send.
- Siz:word - Size of the block.
- Snt: Pointer to word - Amount of data sent (moved to a buffer). In master mode, if interrupt support is enabled, the parameter always returns the same value as the parameter 'Siz' of this method.
- 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_BUSY - The slave device is busy, it does not respond by the acknowledge (only in master mode and when interrupt service is disabled) ERR_BUSOFF - Clock timeout elapsed or device cannot transmit data ERR_TXFULL - Transmitter is full (slave mode only) ERR_ARBITR - Arbitration lost (only when interrupt service is disabled)
-
RecvBlock
- When working as a MASTER, this method writes 7 bits of slave address plus R/W bit = 1 to the I2C bus, then reads the block of characters from the bus and then sends the stop condition. The slave address must be specified before, by the "SelectSlave" method or in bean initialization section, "Slave address init" property. If interrupt service is enabled and the method returns ERR_OK, it doesn't mean that transmission was finished successfully. The state of transmission must be tested by means of events (OnReceiveData, OnError or OnArbitLost). In case of successful transmission, received data is ready after OnReceiveData event is called.
When working as a SLAVE, this method reads a block of characters from the input slave buffer.
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 - Amount of received data. In master mode, if interrupt support is enabled, the parameter always returns the same value as the parameter 'Siz' of this method.
- 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_BUSY - The slave device is busy, it does not respond by an acknowledge (only in master mode and when interrupt service is disabled) ERR_BUSOFF - Clock timeout elapsed or device cannot receive data ERR_RXEMPTY - No data in receiver (slave mode only) ERR_OVERRUN - Overrun error was detected from last character or block receiving (slave mode only) ERR_ARBITR - Arbitration lost (only when interrupt service is disabled)
-
SendStop
- 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', 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 ERR_BUSOFF - Clock timeout elapsed - bus is busy
-
ClearTxBuf
- This method clears all characters in internal slave output buffer. This method is not available for the MASTER mode.
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
-
ClearRxBuf
- This method clears all characters in internal slave input buffer. This method is not available for the MASTER mode.
ANSIC prototype: byte ClearRxBuf(void)
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
GetCharsInTxBuf
- Returns number of characters in the output buffer. In SLAVE mode returns the number of characters in the internal slave output buffer. In MASTER mode returns number of characters to be sent from the user buffer (passed by SendBlock method).
This method is not supported in polling mode.
ANSIC prototype: word GetCharsInTxBuf(void)
- Return value:word - Number of characters in the output buffer.
-
GetCharsInRxBuf
- Returns number of characters in the input buffer. In SLAVE mode returns the number of characters in the internal slave input buffer. In MASTER mode returns number of characters to be received into a user buffer (passed by RecvChar or RecvBlock method).
This method is not supported in polling mode.
ANSIC prototype: word GetCharsInRxBuf(void)
- Return value:word - Number of characters in the input buffer.
-
SelectSlave
- This method selects a new slave for communication by its 7-bit slave address value. The range of the value is from 8 (0001000) to 123 (11111011), the other values are reserved for other purposes of the I2C bus (see I2C bus specification). Any send or receive method directs to or from selected device, until a new slave device is selected by this method. This method is not available 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_BUSY - The device is busy, wait until the current operation is finished. ERR_SPEED - This device does not work in the active speed mode ERR_DISABLED - The device is disabled
-
GetSelected
- This method returns 7-bit slave address value of the slave, which is currently selected for communication with the master. This method is not available for the SLAVE mode.
ANSIC prototype: byte GetSelected(byte *Slv)
- Slv: Pointer to byte - 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
-
SetMode
- This method sets actual operating mode of this bean. This method is available only for the MASTER - SLAVE mode.
Note: If MASTER mode is selected as an operating mode, the device can still be selected as a slave and receive/transmit data. However, it's necessary to select slave operating mode using SetMode( FALSE ) to access this data.
ANSIC prototype: byte SetMode(bool MasterMode)
- MasterMode:bool - Operating mode value:
TRUE - Master FALSE - Slave
- Return value:byte - Error code, possible codes:
ERR_OK - OK ERR_SPEED - This device does not work in the active speed mode
-
GetMode
- This method returns the actual operating mode of this bean.
ANSIC prototype: bool GetMode(void)
- Return value:bool - Actual operating mode value
TRUE - Master FALSE - Slave
- Methods for HC08, HCS08, HCS12, HCS12X and 56800 derivatives.
-
CheckBus
- This method returns the status of the bus. If the START condition has been detected, the method returns 'BeanName'_BUSY. If the STOP condition has been detected, the method returns 'BeanName'_IDLE.
ANSIC prototype: byte CheckBus(void)
- Return value:byte - Status of the bus.
Note: Some methods can be implemented as macros.
|
|
|
Processor ExpertTM and Embedded BeansTM are registered trademarks of UNIS, Ltd.
©1997-2005, UNIS, Ltd.
|
|
|