SMBus Library for MSP430G2xx3 Devices  1.10.00.00
 All Data Structures Functions Variables Enumerations Enumerator Modules Pages
Application API layer

Data Structures

union  SMBus_Ctrl
 SMBus control register. More...
 
struct  SMBus_Phy
 Physical and Data Link Layer object. More...
 
struct  SMBus_Nwk
 Definition of SMBus Network structure. More...
 
union  SMBus_Status
 SMBus Status Register. More...
 
struct  SMBus
 Main SMBus object. More...
 

Macros

#define SMB_PEC_SUPPORTED   (1)
 Define to support Packet Error Checking (PEC)
 
#define SMB_MANUAL_ACK_ENABLE   (0)
 Define to enable Manual ACK workaround. More...
 
#define SMB_CRC8_USE_LOOKUP_TABLE   (1)
 
#define SMB_MAX_PAYLOAD_SIZE   (32)
 Maximum payload as specified by SMBus Spec.
 
#define SMB_MAX_PACKET_SIZE   (SMB_MAX_PAYLOAD_SIZE + 3)
 Max packet size = Payload+PEC+CMD+Len.
 
#define RESPONSE_NTR   0x00
 Default response when there's nothing to send.
 
#define SMBUS_RET_OK   (1)
 Return value when successful.
 
#define SMBUS_RET_ERROR   (-1)
 Return value when an error ocurred.
 

Enumerations

enum  SMBus_Stop {
  SMBus_Stop_No = 0, SMBus_Stop_Immediate, SMBus_Stop_Addr, SMBus_Stop_PreRead,
  SMBus_Stop_Sent
}
 List of stop codes used within the NWK and PHY layers. More...
 
enum  SMBus_NwkState {
  SMBus_NwkState_Idle = 0, SMBus_NwkState_RX, SMBus_NwkState_TX, SMBus_NwkState_TXQuickCMD,
  SMBus_NwkState_TX_Resp, SMBus_NwkState_TX_Block, SMBus_NwkState_RX_Block, SMBus_NwkState_Ending,
  SMBus_NwkState_Error
}
 SMBus network layer states. More...
 
enum  SMBus_ErrorCode { SMBus_ErrorCode_NoError = 0, SMBus_ErrorCode_Packet, SMBus_ErrorCode_Cmd }
 List of error codes used by the application to indicate an error to the library. More...
 
enum  SMBus_State {
  SMBus_State_OK = 0, SMBus_State_DataSizeError, SMBus_State_PECError, SMBus_State_TimeOutError,
  SMBus_State_Slave_FirstByte, SMBus_State_Slave_ByteReceived, SMBus_State_Slave_QCMD, SMBus_State_Slave_CmdComplete,
  SMBus_State_Slave_Error, SMBus_State_Slave_NotReady, SMBus_State_Slave_NTR, SMBus_State_Master_ArbLost,
  SMBus_State_Master_NACK, SMBus_State_Master_Error, SMBus_State_Unknown
}
 SMBus state sent to application layer. More...
 

Functions

void SMBus_processDone (SMBus *smbus)
 Clears the current state of SMBus. More...
 
uint8_t SMBus_getRxPayloadAvailable (SMBus *smbus)
 Returns the number of received bytes from last transaction. More...
 
SMBus_State SMBus_getState (SMBus *smbus)
 Returns the state of the SMBus module. More...
 
void SMBus_enablePEC (SMBus *smbus)
 Enables PEC support. More...
 
void SMBus_disablePEC (SMBus *smbus)
 Disables PEC support. More...
 
void SMBus_slaveInit (SMBus *smbus, uint16_t i2cAddr)
 Initialize the SMBus interface as a slave. More...
 
void SMBus_slaveEnableInt (SMBus *smbus)
 Enables the I2C interrupts for a slave. More...
 
SMBus_State SMBus_slaveProcessInt (SMBus *smbus)
 I2C Interrupt Service routine for a slave. More...
 
void SMBus_masterReset (SMBus *smbus)
 Force reset to SMBus master interface. More...
 
SMBus_State SMBus_slaveProcessTimeoutInt (SMBus *smbus)
 Timer interrupt service routine for slave application. More...
 
void SMBus_slaveSetAddress (SMBus *smbus, uint8_t slaveAddr)
 Set the slave's own I2C address. More...
 
void SMBus_slaveSetRxBuffer (SMBus *smbus, uint8_t *data, uint8_t size)
 Initialize the reception buffer for slave. More...
 
void SMBus_slaveSetTxBuffer (SMBus *smbus, uint8_t *data, uint8_t size)
 Initialize the transmission buffer for slave. More...
 
void SMBus_slaveReportError (SMBus *smbus, SMBus_ErrorCode errorCode)
 Reports an error to SMBus driver from the slave. More...
 
uint8_t SMBus_slaveGetCommand (SMBus *smbus)
 Return the current command (Rxbuffer[0]) received by the slave. More...
 
uint8_t SMBus_slaveClearStatusReg (SMBus *smbus, uint8_t val)
 Clear the slave's status register. More...
 
uint8_t SMBus_slaveWriteCtrlReg (SMBus *smbus, uint8_t val)
 Write a value to the slave's control register. More...
 
void SMBus_masterInit (SMBus *smbus, uint16_t i2cAddr, uint32_t busClk)
 Initialize the SMBus Interface for a master. More...
 
void SMBus_masterEnableInt (SMBus *smbus)
 Enables the I2C interrupts for a master. More...
 
SMBus_State SMBus_masterProcessInt (SMBus *smbus)
 I2C Interrupt Service routine for a master. More...
 
SMBus_State SMBus_masterProcessTimeoutInt (SMBus *smbus)
 Timer interrupt service routine for a master. More...
 
int8_t SMBus_masterProcessCall (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t *rxData)
 Sends a process call to a slave. More...
 
int8_t SMBus_masterProcessCallBlock (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t txSize, uint8_t *rxData)
 Sends a block write-block read process call. More...
 
int8_t SMBus_masterSendByte (SMBus *smbus, uint8_t targetAddr, uint8_t txData)
 Sends byte to the slave. More...
 
int8_t SMBus_masterReceiveByte (SMBus *smbus, uint8_t targetAddr, uint8_t *rxData)
 Receive a byte from the slave. More...
 
int8_t SMBus_masterReadBlock (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *rxData)
 Receive a block of data from the slave. More...
 
int8_t SMBus_masterWriteBlock (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t txSize)
 Transmit a block of data to the slave. More...
 
int8_t SMBus_masterReadByteWord (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *rxData, uint8_t rxSize)
 Send a command requesting a byte or word of data from the slave. More...
 
int8_t SMBus_masterWriteByteWord (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t txSize)
 Send a command transmitting a byte or word of data from the slave. More...
 
int8_t SMBus_masterQuickCommand (SMBus *smbus, uint8_t targetAddr, bool write)
 Send a SMBus "quick command". More...
 
int8_t SMBus_masterWaitUntilDone (SMBus *smbus, int32_t timeout)
 Wait until the previous SMBus command is executed. More...
 

Detailed Description

Macro Definition Documentation

#define SMB_CRC8_USE_LOOKUP_TABLE   (1)

Define method used to calculate CRC8:

  • SMB_CRC8_USE_LOOKUP_TABLE == 1 - Use a 256B lookup table (faster but takes more memory)
  • SMB_CRC8_USE_LOOKUP_TABLE == 0 - Calculate CRC8 manually (slower but takes less memory)
#define SMB_MANUAL_ACK_ENABLE   (0)

Define to enable Manual ACK workaround.

The MSP403 eUSCI doesn't support tesing a received byte and NACK/ACK immediately. This workaround uses DMA to stretch SCL low immediately after a byte is received. The DMA ISR is attended and the application then decides if it needs to ACK or NACK the byte This capability is not supported on devices that do not have DMA (e.g. MSP430G2xxx.

Enumeration Type Documentation

List of error codes used by the application to indicate an error to the library.

Enumerator
SMBus_ErrorCode_Packet 

No error detected.

SMBus_ErrorCode_Cmd 

Incorrect packet was received.

Command is not supported

SMBus network layer states.

Enumerator
SMBus_NwkState_RX 

Network is idle and waiting for new packet.

SMBus_NwkState_TX 

Network is receiving a packet.

SMBus_NwkState_TXQuickCMD 

Network is transmitting after receive byte.

SMBus_NwkState_TX_Resp 

Network is sending Quick Command.

SMBus_NwkState_TX_Block 

Network is transmitting a response after restart.

SMBus_NwkState_RX_Block 

Network is transmitting a block.

SMBus_NwkState_Ending 

Network is receiving a block.

SMBus_NwkState_Error 

Network is finishing transfer.

Network error detected

SMBus state sent to application layer.

Enumerator
SMBus_State_DataSizeError 

Nothing special to report.

SMBus_State_PECError 

Incorrect packet size.

SMBus_State_TimeOutError 

PEC Error detected.

SMBus_State_Slave_FirstByte 

Timeout Error.

SMBus_State_Slave_ByteReceived 

1st byte (cmd) received

SMBus_State_Slave_QCMD 

Slave received a byte (2-n)

SMBus_State_Slave_CmdComplete 

Quick Command detected.

SMBus_State_Slave_Error 

Complete packet received by slave.

SMBus_State_Slave_NotReady 

SMBus Slave Error.

SMBus_State_Slave_NTR 

SMBus Buffers haven't been initialized.

SMBus_State_Master_ArbLost 

No Interrupt flags detected.

SMBus_State_Master_NACK 

Arbitration Lost.

SMBus_State_Master_Error 

Unexpected NACKed.

SMBus_State_Unknown 

SMBus Master error.

enum SMBus_Stop

List of stop codes used within the NWK and PHY layers.

Enumerator
SMBus_Stop_Immediate 

No Stop send.

SMBus_Stop_Addr 

Stop is send immediately with Start.

SMBus_Stop_PreRead 

Stop is send after Start.

SMBus_Stop_Sent 

Stop sent before reading next byte.

Function Documentation

void SMBus_disablePEC ( SMBus smbus)

Disables PEC support.

Parameters
smbusPointer to SMBus structure
Returns
None

References SMBus_Ctrl::bits, and SMBus::ctrl.

void SMBus_enablePEC ( SMBus smbus)

Enables PEC support.

Parameters
smbusPointer to SMBus structure
Returns
None

References SMBus_Ctrl::bits, and SMBus::ctrl.

uint8_t SMBus_getRxPayloadAvailable ( SMBus smbus)

Returns the number of received bytes from last transaction.

Parameters
smbusPointer to SMBus structure
Returns
Number of bytes in the RX buffer. PEC byte is not included.

References SMBus_NWK_getRxPayloadSize().

SMBus_State SMBus_getState ( SMBus smbus)

Returns the state of the SMBus module.

Parameters
smbusPointer to SMBus structure
Returns
State of the SMBus module

References SMBus::state.

void SMBus_masterEnableInt ( SMBus smbus)

Enables the I2C interrupts for a master.

This function enables the eUSCI Start,Stop, RX,TX, Timeout interrupts. SMBus_masterInit() must be called before this function. If SMB_MANUAL_ACK_ENABLE is enabled, it enables DMA to handle the RX.

Parameters
smbusPointer to SMBus structure
Returns
none

References SMBus_PHY_masterEnableInt().

Referenced by SMBus_PHY_masterEnable().

void SMBus_masterInit ( SMBus smbus,
uint16_t  i2cAddr,
uint32_t  busClk 
)

Initialize the SMBus Interface for a master.

Initializes the NWK and PHY layers

Parameters
smbusPointer to SMBus structure
i2cAddrBase address of I2C module. For MSP430G2xxx devices, this parameter is ignored.
busClkSMCLK Frequency

References SMBus_Ctrl::bits, SMBus::ctrl, SMBus_Nwk::currentAddr, SMBus_Ctrl::master, SMBus::nwk, SMBus_Nwk::pec, SMBus_Nwk::recByteTxPtr, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxIndex, SMBus_Nwk::rxLen, SMBus_Nwk::rxSize, SMBus_PHY_masterInit(), SMBus::state, SMBus::status, SMBus_Nwk::txBuffPtr, SMBus_Nwk::txIndex, SMBus_Nwk::txLen, SMBus_Nwk::txSize, SMBus_Ctrl::u8byte, and SMBus_Status::u8byte.

int8_t SMBus_masterProcessCall ( SMBus smbus,
uint8_t  targetAddr,
uint8_t  command,
uint8_t *  txData,
uint8_t *  rxData 
)

Sends a process call to a slave.

Send process call to the slave. A command byte and 2 bytes of TX data are required. Two bytes of data will be returned by the slave in rxData.

1 SMBus Process Call command protocol
2 
3 Process Call:
4  1 7 1 1 8 1 8 1 8 1
5  ------------------------------------------------------------------------------------------
6  | S | Slave Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | ...
7  ------------------------------------------------------------------------------------------
8  1 7 1 1 8 1 8 1 1
9  ----------------------------------------------------------------------------
10  | Sr | Slave Address | Rd | A | Data Byte Low | A | Data Byte High | A | P |
11  ----------------------------------------------------------------------------
12 Process Call with PEC:
13  1 7 1 1 8 1 8 1 8 1
14  ------------------------------------------------------------------------------------------
15  | S | Slave Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | ...
16  ------------------------------------------------------------------------------------------
17  1 7 1 1 8 1 8 1 8 1 1
18  --------------------------------------------------------------------------------------
19  | Sr | Slave Address | Rd | A | Data Byte Low | A | Data Byte High | A | PEC | A | P |
20  --------------------------------------------------------------------------------------
21 
22 where:
23  S = Start bit
24  Sr = Reapeated Start bit
25  Wr = Write bit (0)
26  Slave Adddress = SMBus address for slave
27  Command Code = Command byte sent to slave
28  Data Byte = data sent to slave
29  A = Acknowledge from slave
30  PEC = Optional Packet Error Code
31  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
commandCommand byte for slave
txDataTX data buffer
rxDataRX data buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.

int8_t SMBus_masterProcessCallBlock ( SMBus smbus,
uint8_t  targetAddr,
uint8_t  command,
uint8_t *  txData,
uint8_t  txSize,
uint8_t *  rxData 
)

Sends a block write-block read process call.

Send block write-block read process call to the slave. A command byte, length and tx data byte array are required. Ensure that rxData is large enough to hold the data received from the slave.

1 SMBus Block write-block read process call protocol
2 
3 Block write-block read process call:
4  1 7 1 1 8 1 8 1 8 1
5  ----------------------------------------------------------------------------------------
6  | S | Slave Address | Wr | A | Command Code | A | Byte Count = M | A | Data Byte 1 | A | ...
7  ----------------------------------------------------------------------------------------
8  8 1 8 1
9  ------------------- -------------------
10  | Data Byte 2 | A | ... | Data Byte M | A | ...
11  ------------------- -------------------
12  1 7 1 1 8 1 8 1
13  ----------------------------------------------------------------------
14  | Sr | Slave Address | Rd | A | Byte Count = N | A | Data Byte 1 | A | ...
15  ----------------------------------------------------------------------
16  8 1 8 1 1
17  ------------------- -----------------------
18  | Data Byte 2 | A | ... | Data Byte N | A | P |
19  ------------------- -----------------------
20 Block write-block read process call with PEC:
21  1 7 1 1 8 1 8 1 8 1
22  ----------------------------------------------------------------------------------------
23  | S | Slave Address | Wr | A | Command Code | A | Byte Count = M | A | Data Byte 1 | A | ...
24  ----------------------------------------------------------------------------------------
25  8 1 8 1
26  ------------------- -------------------
27  | Data Byte 2 | A | ... | Data Byte M | A | ...
28  ------------------- -------------------
29  1 7 1 1 8 1 8 1
30  ----------------------------------------------------------------------
31  | Sr | Slave Address | Rd | A | Byte Count = N | A | Data Byte 1 | A | ...
32  ----------------------------------------------------------------------
33  8 1 8 1 8 1 1
34  ------------------- ---------------------------------
35  | Data Byte 2 | A | ... | Data Byte N | A | PEC | A | P |
36  ------------------- ---------------------------------
37 
38 where:
39  S = Start bit
40  Sr = Reapeated Start bit
41  Wr = Write bit (0)
42  Rd = Read bit (1)
43  Slave Adddress = SMBus address for slave
44  Command Code = Command byte sent to slave
45  Data Byte = data sent to slave
46  A = Acknowledge from slave
47  PEC = Optional Packet Error Code
48  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
commandCommand byte for slave
txDataTX data buffer
txSizeSize of the txData buffer
rxDataRX data buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMB_MAX_PAYLOAD_SIZE, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.

SMBus_State SMBus_masterProcessInt ( SMBus smbus)

I2C Interrupt Service routine for a master.

Handles the interrupts for SMBus passing information to NWK layer Should be called by application when USCI interrupt is detected

Parameters
smbusPointer to SMBus structure
Returns
Processing State (SMBus_State)

References SMBus_PHY_masterProcessInt().

SMBus_State SMBus_masterProcessTimeoutInt ( SMBus smbus)

Timer interrupt service routine for a master.

Handles the interrupts for SMBus tiemout processing for USCI devices. Should be called by application when Timer interrupt is detected

Parameters
smbusPointer to SMBus structure
Returns
Processing State (SMBus_State):

References SMBus_PHY_masterProcessTimeoutInt().

int8_t SMBus_masterQuickCommand ( SMBus smbus,
uint8_t  targetAddr,
bool  write 
)

Send a SMBus "quick command".

A "quick command" is only a trigger. There is no data sent or received.

1 SMBus Quick Commmand Protocol:
2  1 7 1 1 1
3  -------------------------------------
4  | S | Slave Address | Rd/Wr | A | P |
5  -------------------------------------
6 where:
7  S = Start bit
8  Rd/Wr = Read or Write bit
9  Slave Adddress = SMBus address for slave
10  A = Acknowledge from slave
11  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
writetrue if this is a write command, false if this is a read command
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TXQuickCMD, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.

int8_t SMBus_masterReadBlock ( SMBus smbus,
uint8_t  targetAddr,
uint8_t  command,
uint8_t *  rxData 
)

Receive a block of data from the slave.

Send block data receive call to the slave. A command byte, length and rx data byte array are required. Ensure that rxData is large enough to hold the data received from the slave.

1 SMBus Block Read command protocol
2 
3 Block Read:
4  1 7 1 1 8 1 1 8 1 1
5  -------------------------------------------------------------------------------
6  | S | Slave Address | Wr | A | Command Code | A | Sr | Slave Address | Rd | A | ...
7  -------------------------------------------------------------------------------
8  8 1 8 1 8 1 8 1 1
9  ----------------------------------------------------------------------------------------
10  | Byte Count = N | A | Data Byte 1 | A | Data Byte 2 | A | ... | Data Byte N | A | P |
11  ----------------------------------------------------------------------------------------
12 Block Read with PEC:
13  1 7 1 1 8 1 1 8 1 1
14  -------------------------------------------------------------------------------
15  | S | Slave Address | Wr | A | Command Code | A | Sr | Slave Address | Rd | A | ...
16  -------------------------------------------------------------------------------
17  8 1 8 1 8 1 8 1
18  ------------------------------------------------------------------------------------
19  | Byte Count = N | A | Data Byte 1 | A | Data Byte 2 | A | ... | Data Byte N | A |...
20  ------------------------------------------------------------------------------------
21  8 1 1
22  ---------------
23  | PEC | A | P |
24  ---------------
25 
26 where:
27  S = Start bit
28  Sr = Reapeated Start bit
29  Wr = Write bit (0)
30  Rd = Read bit (1)
31  Slave Adddress = SMBus address for slave
32  Command Code = Command byte sent to slave
33  Data Byte = data sent to slave
34  A = Acknowledge from slave
35  PEC = Optional Packet Error Code
36  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
commandCommand byte for slave
rxDataRX data buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.

int8_t SMBus_masterReadByteWord ( SMBus smbus,
uint8_t  targetAddr,
uint8_t  command,
uint8_t *  rxData,
uint8_t  rxSize 
)

Send a command requesting a byte or word of data from the slave.

1 SMBus Read ByteWord command protocol
2 
3 Read Byte:
4  1 7 1 1 8 1 8 1 1 8 1 1
5  ----------------------------------------------------------------------------------------------
6  | S | Slave Address | Wr | A | Command Code | S | Slave Address | Rd | A | Data Byte | A | P |
7  ----------------------------------------------------------------------------------------------
8 Read Byte with PEC:
9  1 7 1 1 8 1 8 1 1 8 1 1
10  ----------------------------------------------------------------------------------------------
11  | S | Slave Address | Wr | A | Command Code | S | Slave Address | Rd | A | Data Byte | A | P | ...
12  ----------------------------------------------------------------------------------------------
13  8 1 1
14  ---------------
15  | PEC | A | P |
16  ---------------
17 
18 Read Word:
19  1 7 1 1 8 1 8 1 1 8 1 1
20  --------------------------------------------------------------------------------------------------
21  | S | Slave Address | Wr | A | Command Code | S | Slave Address | Rd | A | Data Byte Low | A | P | ...
22  --------------------------------------------------------------------------------------------------
23  8 1 1
24  --------------------------
25  | Data Byte High | A | P |
26  --------------------------
27 Read Word with PEC:
28  1 7 1 1 8 1 8 1 1 8 1 1
29  --------------------------------------------------------------------------------------------------
30  | S | Slave Address | Wr | A | Command Code | S | Slave Address | Rd | A | Data Byte Low | A | P | ...
31  --------------------------------------------------------------------------------------------------
32  8 1 1 8 1 1
33  ----------------------------------------
34  | Data Byte High | A | P | PEC | A | P |
35  ----------------------------------------
36 
37 where:
38  S = Start bit
39  Wr = Read bit (0)
40  Rd = Read bit (1)
41  Slave Adddress = SMBus address for slave
42  Command Code = Command byte sent to slave
43  Data Byte = data sent to slave
44  A = Acknowledge from slave
45  PEC = Optional Packet Error Code
46  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
commandCommand byte for slave
rxDataRX data buffer
rxSizeMust be 1 or 2 bytes
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.

int8_t SMBus_masterReceiveByte ( SMBus smbus,
uint8_t  targetAddr,
uint8_t *  rxData 
)

Receive a byte from the slave.

1 SMBus Receive Byte command protocol
2 
3  1 7 1 1 8 1 1
4  --------------------------------------------------
5  | S | Slave Address | Rd | A | Data Byte | A | P |
6  --------------------------------------------------
7 With PEC:
8  1 7 1 1 8 1 8 1 1
9  ------------------------------------------------------------
10  | S | Slave Address | Rd | A | Data Byte | A | PEC | A | P |
11  ------------------------------------------------------------
12 
13 where:
14  S = Start bit
15  Rd = Read bit (1)
16  Slave Adddress = SMBus address for slave
17  Data Byte = data received from slave
18  A = Acknowledge from slave
19  PEC = Optional Packet Error Code
20  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
rxDataRX data buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startRxTransfer(), SMBus_NwkState_RX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.

void SMBus_masterReset ( SMBus smbus)

Force reset to SMBus master interface.

Resets the network and PHY layers

Parameters
smbusPointer to SMBus structure
Returns
None

References SMBus_NWK_masterReset().

int8_t SMBus_masterSendByte ( SMBus smbus,
uint8_t  targetAddr,
uint8_t  txData 
)

Sends byte to the slave.

1 SMBus Send Byte command protocol
2 
3  1 7 1 1 8 1 1
4  ---------------------------------------------------
5  | S | Slave Address | Wr | A | Data Byte | A | P |
6  ---------------------------------------------------
7 Send Byte with PEC:
8  1 7 1 1 8 1 8 1 1
9  ------------------------------------------------------------
10  | S | Slave Address | Wr | A | Data Byte | A | PEC | A | P |
11  ------------------------------------------------------------
12 
13 where:
14  S = Start bit
15  Wr = Write bit (0)
16  Slave Adddress = SMBus address for slave
17  Data Byte = data sent to slave
18  A = Acknowledge from slave
19  PEC = Optional Packet Error Code
20  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
txDataTX data buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.

int8_t SMBus_masterWaitUntilDone ( SMBus smbus,
int32_t  timeout 
)

Wait until the previous SMBus command is executed.

Parameters
smbusPointer to SMBus structure
timeoutSoftware timeout
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus::nwk, SMBUS_RET_ERROR, and SMBUS_RET_OK.

int8_t SMBus_masterWriteBlock ( SMBus smbus,
uint8_t  targetAddr,
uint8_t  command,
uint8_t *  txData,
uint8_t  txSize 
)

Transmit a block of data to the slave.

Send block of data to the slave. A command byte, length and tx data byte array are required.

1 SMBus Block Write command protocol
2 
3 Block Write:
4  1 7 1 1 8 1 8 1 8 1
5  ----------------------------------------------------------------------------------------
6  | S | Slave Address | Wr | A | Command Code | A | Byte Count = N | A | Data Byte 1 | A | ...
7  ----------------------------------------------------------------------------------------
8  8 1 8 1 1
9  -------------------- -----------------------
10  | Data Byte 2 | A | ... | Data Byte N | A | P |
11  -------------------- -----------------------
12 Block Write with PEC:
13  1 7 1 1 8 1 8 1 8 1
14  ----------------------------------------------------------------------------------------
15  | S | Slave Address | Wr | A | Command Code | A | Byte Count = N | A | Data Byte 1 | A | ...
16  ----------------------------------------------------------------------------------------
17  8 1 8 1 8 1 1
18  -------------------- ---------------------------------
19  | Data Byte 2 | A | ... | Data Byte N | A | PEC | A | P |
20  -------------------- ---------------------------------
21 
22 where:
23  S = Start bit
24  Wr = Write bit (0)
25  Slave Adddress = SMBus address for slave
26  Command Code = Command byte sent to slave
27  Data Byte = data sent to slave
28  A = Acknowledge from slave
29  PEC = Optional Packet Error Code
30  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
commandCommand byte for slave
txDataTX data buffer
txSizeSize of the txData buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxLen, SMB_MAX_PAYLOAD_SIZE, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.

int8_t SMBus_masterWriteByteWord ( SMBus smbus,
uint8_t  targetAddr,
uint8_t  command,
uint8_t *  txData,
uint8_t  txSize 
)

Send a command transmitting a byte or word of data from the slave.

1 SMBus Write ByteWord command protocol
2 
3 Write Byte:
4  1 7 1 1 8 1 8 1 1
5  ---------------------------------------------------------------------
6  | S | Slave Address | Wr | A | Command Code | A | Data Byte | A | P |
7  ---------------------------------------------------------------------
8 Write Byte with PEC:
9  1 7 1 1 8 1 8 1 8 1 1
10  -------------------------------------------------------------------------------
11  | S | Slave Address | Wr | A | Command Code | A | Data Byte | A | PEC | A | P |
12  -------------------------------------------------------------------------------
13 
14 Write Word:
15  1 7 1 1 8 1 8 1 8 1 1
16  ----------------------------------------------------------------------------------------------
17  | S | Slave Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | P |
18  ----------------------------------------------------------------------------------------------
19 Write Word with PEC:
20  1 7 1 1 8 1 8 1 8 1 8 1 1
21  --------------------------------------------------------------------------------------------------------
22  | S | Slave Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | PEC | A | P |
23  --------------------------------------------------------------------------------------------------------
24 
25 where:
26  S = Start bit
27  Wr = Write bit (0)
28  Slave Adddress = SMBus address for slave
29  Command Code = Command byte sent to slave
30  Data Byte = data sent to slave
31  A = Acknowledge from slave
32  PEC = Optional Packet Error Code
33  P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrSlave address
commandCommand byte for slave
txDataTX data buffer
txSizeMust be 1 or 2 bytes
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.

void SMBus_processDone ( SMBus smbus)

Clears the current state of SMBus.

Must be called by application in order to clear the state machine when a byte/packet was processed

Parameters
smbusPointer to SMBus structure
Returns
None

References SMBus::state.

uint8_t SMBus_slaveClearStatusReg ( SMBus smbus,
uint8_t  val 
)

Clear the slave's status register.

Parameters
smbusPointer to SMBus structure
valBits cleared from status register (1=X, 0=clear)
Returns
Value of Status register after clearing flags

References SMBus::status, and SMBus_Status::u8byte.

void SMBus_slaveEnableInt ( SMBus smbus)

Enables the I2C interrupts for a slave.

This function enables the eUSCI Start,Stop, RX,TX, Timeout interrupts If SMB_MANUAL_ACK_ENABLE is enabled, it enables DMA to handle the RX SMBus_slaveInit() must be called before this function

Parameters
smbusPointer to SMBus structure
Returns
None

References SMBus_PHY_slaveEnableInt().

Referenced by SMBus_PHY_slaveEnable().

uint8_t SMBus_slaveGetCommand ( SMBus smbus)

Return the current command (Rxbuffer[0]) received by the slave.

Parameters
smbusPointer to SMBus structure
Returns
Current command byte

References SMBus_Nwk::currentCmd, and SMBus::nwk.

void SMBus_slaveInit ( SMBus smbus,
uint16_t  i2cAddr 
)

Initialize the SMBus interface as a slave.

Initializes the NWK and PHY layers.

Parameters
smbusPointer to SMBus structure
i2cAddrBase address of I2C module. For MSP430G2xxx devices, this parameter is ignored.
Returns
None

References SMBus_Ctrl::bits, SMBus::ctrl, SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Ctrl::master, SMBus::nwk, SMBus_Nwk::pec, SMBus_Nwk::recByteTxPtr, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxIndex, SMBus_Nwk::rxLen, SMBus_Nwk::rxSize, SMBus_PHY_slaveInit(), SMBus::state, SMBus::status, SMBus_Nwk::txBuffPtr, SMBus_Nwk::txIndex, SMBus_Nwk::txLen, SMBus_Nwk::txSize, SMBus_Ctrl::u8byte, and SMBus_Status::u8byte.

SMBus_State SMBus_slaveProcessInt ( SMBus smbus)

I2C Interrupt Service routine for a slave.

Handles the interrupts for SMBus passing information to NWK layer Should be called by application when USCI/DMA interrupt is detected Note that this routine also checks the DMA due to the SW ACK workaround if SMB_MANUAL_ACK_ENABLE is defined.

Parameters
smbusPointer to SMBus structure
Returns
Processing State (SMBus_State)
  • SMBus_State_Slave_NotReady - Packet is not ready
  • SMBus_State_Slave_FirstByte - First byte received (application can use it to validate the command)
  • SMBus_State_Slave_ByteReceived - Byte 2+ received (application can use it to validate each byte)
  • SMBus_State_Slave_QCMD - Quick command received
  • SMBus_State_Slave_CmdComplete - Packet complete and if PEC enabled, validated.

References SMBus_PHY_slaveProcessInt(), SMBus_State_Slave_NTR, and SMBus::state.

SMBus_State SMBus_slaveProcessTimeoutInt ( SMBus smbus)

Timer interrupt service routine for slave application.

Handles the interrupts for SMBus tiemout processing for USCI devices. Should be called by application when Timer interrupt is detected

Parameters
smbusPointer to SMBus structure
Returns
Processing State (SMBus_State):
  • SMBus_State_TimeOutError - Timeout ocurred, SMBUS has been restarted

References SMBus_PHY_slaveProcessTimeoutInt().

void SMBus_slaveReportError ( SMBus smbus,
SMBus_ErrorCode  errorCode 
)

Reports an error to SMBus driver from the slave.

Used to signal an error when incorrect command/data is detected by the slave

Parameters
smbusPointer to SMBus structure
errorCodeSMBus_ErrorCode
Returns
None

References SMBus_Status::bits, SMBus_Status::cmdErr, SMBus::nwk, SMBus_Status::packErr, SMBus_ErrorCode_Cmd, SMBus_ErrorCode_Packet, SMBus_NwkState_Error, and SMBus::status.

void SMBus_slaveSetAddress ( SMBus smbus,
uint8_t  slaveAddr 
)

Set the slave's own I2C address.

Parameters
smbusPointer to SMBus structure
slaveAddrSlave I2C address
Returns
None

References SMBus_Ctrl::bits, SMBus::ctrl, SMBus::ownSlaveAddr, SMBus_Ctrl::phyEn, and SMBus_PHY_enable().

void SMBus_slaveSetRxBuffer ( SMBus smbus,
uint8_t *  data,
uint8_t  size 
)

Initialize the reception buffer for slave.

Parameters
smbusPointer to SMBus structure
dataPointer to Application RX buffer
sizeMaximum size of buffer
Returns
None

References SMBus::nwk, SMBus_Nwk::rxBuffPtr, and SMBus_Nwk::rxSize.

void SMBus_slaveSetTxBuffer ( SMBus smbus,
uint8_t *  data,
uint8_t  size 
)

Initialize the transmission buffer for slave.

Parameters
smbusPointer to SMBus structure
dataPointer to Application TX buffer
sizeMaximum size of buffer
Returns
None

References SMBus::nwk, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txSize.

uint8_t SMBus_slaveWriteCtrlReg ( SMBus smbus,
uint8_t  val 
)

Write a value to the slave's control register.

Parameters
smbusPointer to SMBus structure
valValue being written to the Control register
Returns
Value of Control register after write

References SMBus::ctrl, SMBus_Ctrl::u8byte, and SMBus_Ctrl::writeableBits.


Copyright 2015, Texas Instruments Incorporated