SMBusLibrary  1.0
Data Structures | Macros | Enumerations | Functions
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_CRC8_USE_LOOKUP_TABLE   (1)
 
#define SMB_MAX_PAYLOAD_SIZE   (255)
 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_After_Transfer = 0,
  SMBus_No_Stop_After_Transfer
}
 List of stop codes used within the NWK and PHY layers.
 
enum  SMBus_Start {
  SMBus_Start_Before_Transfer = 0,
  SMBus_No_Start_Before_Transfer
}
 List of start codes used within the NWK and PHY layers.
 
enum  SMBus_Auto_Ack {
  SMBus_Auto_Ack_Last_Byte = 0,
  SMBus_No_Auto_Ack_Last_Byte
}
 List of auto ack codes used within the NWK and PHY layers.
 
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_Byte_Count,
  SMBus_NwkState_RX_Block_Payload,
  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_Target_FirstByte,
  SMBus_State_Target_ByteReceived,
  SMBus_State_Target_QCMD,
  SMBus_State_Target_CmdComplete,
  SMBus_State_Target_Error,
  SMBus_State_Target_NotReady,
  SMBus_State_Target_NTR,
  SMBus_State_Controller_ArbLost,
  SMBus_State_Controller_NACK,
  SMBus_State_Controller_Error,
  SMBus_State_Unknown
}
 SMBus state sent to application layer. More...
 

Functions

void SMBus_processDone (SMBus *smbus)
 Clears the current state of SMBus. More...
 
uint16_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_targetInit (SMBus *smbus, I2C_Regs *i2cAddr)
 Initialize the SMBus interface as a target. More...
 
void SMBus_targetEnableInt (SMBus *smbus)
 Enables the I2C interrupts for a target. More...
 
SMBus_State SMBus_targetProcessInt (SMBus *smbus)
 I2C Interrupt Service routine for a target. More...
 
void SMBus_controllerReset (SMBus *smbus)
 Force reset to SMBus controller interface. More...
 
void SMBus_targetSetAddress (SMBus *smbus, uint8_t targetAddr)
 Set the target's own I2C address. More...
 
void SMBus_targetSetRxBuffer (SMBus *smbus, uint8_t *data, uint16_t size)
 Initialize the reception buffer for target. More...
 
void SMBus_targetSetTxBuffer (SMBus *smbus, uint8_t *data, uint16_t size)
 Initialize the transmission buffer for target. More...
 
void SMBus_targetReportError (SMBus *smbus, SMBus_ErrorCode errorCode)
 Reports an error to SMBus driver from the target. More...
 
uint8_t SMBus_targetGetCommand (SMBus *smbus)
 Return the current command (Rxbuffer[0]) received by the target. More...
 
uint8_t SMBus_targetClearStatusReg (SMBus *smbus, uint8_t val)
 Clear the target's status register. More...
 
uint8_t SMBus_targetWriteCtrlReg (SMBus *smbus, uint8_t val)
 Write a value to the target's control register. More...
 
void SMBus_controllerInit (SMBus *smbus, I2C_Regs *i2cAddr, uint32_t busClk)
 Initialize the SMBus Interface for a controller. More...
 
void SMBus_controllerEnableInt (SMBus *smbus)
 Enables the I2C interrupts for a controller. More...
 
SMBus_State SMBus_controllerProcessInt (SMBus *smbus)
 I2C Interrupt Service routine for a controller. More...
 
int8_t SMBus_controllerProcessCall (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t *rxData)
 Sends a process call to a target. More...
 
int8_t SMBus_controllerProcessCallBlock (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_controllerSendByte (SMBus *smbus, uint8_t targetAddr, uint8_t txData)
 Sends byte to the target. More...
 
int8_t SMBus_controllerReadByteWord (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *rxData, uint8_t rxSize)
 Receive a byte from the target. More...
 
int8_t SMBus_controllerWriteByteWord (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 target. More...
 
int8_t SMBus_controllerQuickCommand (SMBus *smbus, uint8_t targetAddr, bool write)
 Send a SMBus "quick command". More...
 
int8_t SMBus_controllerWaitUntilDone (SMBus *smbus, int32_t timeout)
 Wait until the previous SMBus command is executed. More...
 

Detailed Description

Macro Definition Documentation

§ SMB_CRC8_USE_LOOKUP_TABLE

#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)

Enumeration Type Documentation

§ SMBus_NwkState

SMBus network layer states.

Enumerator
SMBus_NwkState_Idle 

Network is idle and waiting for new packet

SMBus_NwkState_RX 

Network is receiving a packet

SMBus_NwkState_TX 

Network is transmitting after receive byte

SMBus_NwkState_TXQuickCMD 

Network is sending Quick Command

SMBus_NwkState_TX_Resp 

Network is transmitting a response after restart

SMBus_NwkState_TX_Block 

Network is transmitting a block

SMBus_NwkState_RX_Block_Byte_Count 

Network is receiving a block

SMBus_NwkState_RX_Block_Payload 

Network is receiving a block

SMBus_NwkState_Ending 

Network is finishing transfer

SMBus_NwkState_Error 

Network error detected

§ SMBus_ErrorCode

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

Enumerator
SMBus_ErrorCode_NoError 

No error detected

SMBus_ErrorCode_Packet 

Incorrect packet was received

SMBus_ErrorCode_Cmd 

Command is not supported

§ SMBus_State

SMBus state sent to application layer.

Enumerator
SMBus_State_OK 

Nothing special to report

SMBus_State_DataSizeError 

Incorrect packet size

SMBus_State_PECError 

PEC Error detected

SMBus_State_TimeOutError 

Timeout Error

SMBus_State_Target_FirstByte 

1st byte (cmd) received

SMBus_State_Target_ByteReceived 

Target received a byte (2-n)

SMBus_State_Target_QCMD 

Quick Command detected

SMBus_State_Target_CmdComplete 

Complete packet received by target

SMBus_State_Target_Error 

SMBus Target Error

SMBus_State_Target_NotReady 

SMBus Buffers haven't been initialized

SMBus_State_Target_NTR 

No Interrupt flags detected

SMBus_State_Controller_ArbLost 

Arbitration Lost

SMBus_State_Controller_NACK 

Unexpected NACKed

SMBus_State_Controller_Error 

SMBus Controller error

SMBus_State_Unknown 

SMBus State Unknown

Function Documentation

§ SMBus_processDone()

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_OK, and SMBus::state.

§ SMBus_getRxPayloadAvailable()

uint16_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_getState()

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.

§ SMBus_enablePEC()

void SMBus_enablePEC ( SMBus smbus)

Enables PEC support.

Parameters
smbusPointer to SMBus structure
Returns
None

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

§ SMBus_disablePEC()

void SMBus_disablePEC ( SMBus smbus)

Disables PEC support.

Parameters
smbusPointer to SMBus structure
Returns
None

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

§ SMBus_targetInit()

void SMBus_targetInit ( SMBus smbus,
I2C_Regs *  i2cAddr 
)

§ SMBus_targetEnableInt()

void SMBus_targetEnableInt ( SMBus smbus)

Enables the I2C interrupts for a target.

This function enables the I2C Start, Stop, RX, TX, Timeout interrupts

Parameters
smbusPointer to SMBus structure
Returns
None

References SMBus_PHY_targetEnableInt().

Referenced by SMBus_PHY_targetEnable().

§ SMBus_targetProcessInt()

SMBus_State SMBus_targetProcessInt ( SMBus smbus)

I2C Interrupt Service routine for a target.

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

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

References SMBus_PHY_targetProcessInt(), SMBus_State_Target_NTR, and SMBus::state.

§ SMBus_controllerReset()

void SMBus_controllerReset ( SMBus smbus)

Force reset to SMBus controller interface.

Resets the network and PHY layers

Parameters
smbusPointer to SMBus structure
Returns
None

References SMBus_NWK_controllerReset().

§ SMBus_targetSetAddress()

void SMBus_targetSetAddress ( SMBus smbus,
uint8_t  targetAddr 
)

Set the target's own I2C address.

Parameters
smbusPointer to SMBus structure
targetAddrTarget I2C address
Returns
None

References SMBus::ownTargetAddr.

§ SMBus_targetSetRxBuffer()

void SMBus_targetSetRxBuffer ( SMBus smbus,
uint8_t *  data,
uint16_t  size 
)

Initialize the reception buffer for target.

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.

§ SMBus_targetSetTxBuffer()

void SMBus_targetSetTxBuffer ( SMBus smbus,
uint8_t *  data,
uint16_t  size 
)

Initialize the transmission buffer for target.

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.

§ SMBus_targetReportError()

void SMBus_targetReportError ( SMBus smbus,
SMBus_ErrorCode  errorCode 
)

Reports an error to SMBus driver from the target.

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

Parameters
smbusPointer to SMBus structure
errorCodeSMBus_ErrorCode
Returns
None

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

§ SMBus_targetGetCommand()

uint8_t SMBus_targetGetCommand ( SMBus smbus)

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

Parameters
smbusPointer to SMBus structure
Returns
Current command byte

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

§ SMBus_targetClearStatusReg()

uint8_t SMBus_targetClearStatusReg ( SMBus smbus,
uint8_t  val 
)

Clear the target'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.

§ SMBus_targetWriteCtrlReg()

uint8_t SMBus_targetWriteCtrlReg ( SMBus smbus,
uint8_t  val 
)

Write a value to the target'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, SMBus_Ctrl::writeableBits, and SMBus_Ctrl::writeBits.

§ SMBus_controllerInit()

void SMBus_controllerInit ( SMBus smbus,
I2C_Regs *  i2cAddr,
uint32_t  busClk 
)

§ SMBus_controllerEnableInt()

void SMBus_controllerEnableInt ( SMBus smbus)

Enables the I2C interrupts for a controller.

This function enables the I2C Start, Stop, RX, TX, Timeout interrupts. SMBus_controllerInit() must be called before this function.

Parameters
smbusPointer to SMBus structure
Returns
none

References SMBus_PHY_controllerEnableInt().

Referenced by SMBus_PHY_controllerEnable().

§ SMBus_controllerProcessInt()

SMBus_State SMBus_controllerProcessInt ( SMBus smbus)

I2C Interrupt Service routine for a controller.

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

Parameters
smbusPointer to SMBus structure
Returns
Processing State (SMBus_State)

References SMBus_PHY_controllerProcessInt().

§ SMBus_controllerProcessCall()

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

Sends a process call to a target.

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

SMBus Process Call command protocol
Process Call:
1 7 1 1 8 1 8 1 8 1
------------------------------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | ...
------------------------------------------------------------------------------------------
1 7 1 1 8 1 8 1 1
----------------------------------------------------------------------------
| Sr | Target Address | Rd | A | Data Byte Low | A | Data Byte High | A | P |
----------------------------------------------------------------------------
Process Call with PEC:
1 7 1 1 8 1 8 1 8 1
------------------------------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | ...
------------------------------------------------------------------------------------------
1 7 1 1 8 1 8 1 8 1 1
--------------------------------------------------------------------------------------
| Sr | Target Address | Rd | A | Data Byte Low | A | Data Byte High | A | PEC | A | P |
--------------------------------------------------------------------------------------
where:
S = Start bit
Sr = Reapeated Start bit
Wr = Write bit (0)
Target Adddress = SMBus address for target
Command Code = Command byte sent to target
Data Byte = data sent to target
A = Acknowledge from target
PEC = Optional Packet Error Code
P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrTarget address
commandCommand byte for target
txDataTX data buffer
rxDataRX data buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

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

§ SMBus_controllerProcessCallBlock()

int8_t SMBus_controllerProcessCallBlock ( 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 target. A command byte, length and tx data byte array are required. Ensure that rxData is large enough to hold the data received from the target.

SMBus Block write-block read process call protocol
Block write-block read process call:
1 7 1 1 8 1 8 1 8 1
----------------------------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Byte Count = M | A | Data Byte 1 | A | ...
----------------------------------------------------------------------------------------
8 1 8 1
------------------- -------------------
| Data Byte 2 | A | ... | Data Byte M | A | ...
------------------- -------------------
1 7 1 1 8 1 8 1
----------------------------------------------------------------------
| Sr | Target Address | Rd | A | Byte Count = N | A | Data Byte 1 | A | ...
----------------------------------------------------------------------
8 1 8 1 1
------------------- -----------------------
| Data Byte 2 | A | ... | Data Byte N | A | P |
------------------- -----------------------
Block write-block read process call with PEC:
1 7 1 1 8 1 8 1 8 1
----------------------------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Byte Count = M | A | Data Byte 1 | A | ...
----------------------------------------------------------------------------------------
8 1 8 1
------------------- -------------------
| Data Byte 2 | A | ... | Data Byte M | A | ...
------------------- -------------------
1 7 1 1 8 1 8 1
----------------------------------------------------------------------
| Sr | Target Address | Rd | A | Byte Count = N | A | Data Byte 1 | A | ...
----------------------------------------------------------------------
8 1 8 1 8 1 1
------------------- ---------------------------------
| Data Byte 2 | A | ... | Data Byte N | A | PEC | A | P |
------------------- ---------------------------------
where:
S = Start bit
Sr = Reapeated Start bit
Wr = Write bit (0)
Rd = Read bit (1)
Target Adddress = SMBus address for target
Command Code = Command byte sent to target
Data Byte = data sent to target
A = Acknowledge from target
PEC = Optional Packet Error Code
P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrTarget address
commandCommand byte for target
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::eState, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMB_MAX_PAYLOAD_SIZE, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.

§ SMBus_controllerSendByte()

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

Sends byte to the target.

SMBus Send Byte command protocol
1 7 1 1 8 1 1
---------------------------------------------------
| S | Target Address | Wr | A | Data Byte | A | P |
---------------------------------------------------
Send Byte with PEC:
1 7 1 1 8 1 8 1 1
------------------------------------------------------------
| S | Target Address | Wr | A | Data Byte | A | PEC | A | P |
------------------------------------------------------------
where:
S = Start bit
Wr = Write bit (0)
Target Adddress = SMBus address for target
Data Byte = data sent to target
A = Acknowledge from target
PEC = Optional Packet Error Code
P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrTarget address
txDataTX data buffer
Returns
SMBUS_RET_ERROR, or SMBUS_RET_OK

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

§ SMBus_controllerReadByteWord()

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

Receive a byte from the target.

SMBus Receive Byte command protocol
1 7 1 1 8 1 1
--------------------------------------------------
| S | Target Address | Rd | A | Data Byte | A | P |
--------------------------------------------------
With PEC:
1 7 1 1 8 1 8 1 1
------------------------------------------------------------
| S | Target Address | Rd | A | Data Byte | A | PEC | A | P |
------------------------------------------------------------
where:
S = Start bit
Rd = Read bit (1)
Target Adddress = SMBus address for target
Data Byte = data received from target
A = Acknowledge from target
PEC = Optional Packet Error Code
P = Stop bit
~~~~~~~~ */
//
//
//
//*****************************************************************************
extern int8_t SMBus_controllerReceiveByte(SMBus *smbus,
uint8_t targetAddr,
uint8_t *rxData);
//*****************************************************************************
//
//
//
/**

SMBus Block Read command protocol

Block Read:

1 7 1 1 8 1 1 8 1 1

| S | Target Address | Wr | A | Command Code | A | Sr | Target Address | Rd | A | ...

8 1 8 1 8 1 8 1 1

| Byte Count = N | A | Data Byte 1 | A | Data Byte 2 | A | ... | Data Byte N | A | P |

Block Read with PEC:

1 7 1 1 8 1 1 8 1 1

| S | Target Address | Wr | A | Command Code | A | Sr | Target Address | Rd | A | ...

8 1 8 1 8 1 8 1

| Byte Count = N | A | Data Byte 1 | A | Data Byte 2 | A | ... | Data Byte N | A |...

8 1 1

| PEC | A | P |

where: 
    S = Start bit
    Sr = Reapeated Start bit
    Wr = Write bit (0)
    Rd = Read bit (1)
    Target Adddress = SMBus address for target
    Command Code = Command byte sent to target
    Data Byte = data sent to target
    A = Acknowledge from target
    PEC = Optional Packet Error Code
    P = Stop bit
//
//
//
//*****************************************************************************
extern int8_t SMBus_controllerReadBlock(SMBus *smbus,
uint8_t targetAddr,
uint8_t command,
uint8_t *rxData);
//*****************************************************************************
//
//
//
/**

SMBus Block Write command protocol

Block Write:

1 7 1 1 8 1 8 1 8 1

| S | Target Address | Wr | A | Command Code | A | Byte Count = N | A | Data Byte 1 | A | ...

8 1 8 1 1


| Data Byte 2 | A | ... | Data Byte N | A | P |


Block Write with PEC:

1 7 1 1 8 1 8 1 8 1

| S | Target Address | Wr | A | Command Code | A | Byte Count = N | A | Data Byte 1 | A | ...

8 1 8 1 8 1 1


| Data Byte 2 | A | ... | Data Byte N | A | PEC | A | P |


where: 
    S = Start bit
    Wr = Write bit (0)
    Target Adddress = SMBus address for target
    Command Code = Command byte sent to target
    Data Byte = data sent to target
    A = Acknowledge from target
    PEC = Optional Packet Error Code
    P = Stop bit
//
//
//
//*****************************************************************************
extern int8_t SMBus_controllerWriteBlock(SMBus *smbus,
uint8_t targetAddr,
uint8_t command,
uint8_t *txData,
uint16_t txSize);
//*****************************************************************************
//
//
//
/*

SMBus Read ByteWord command protocol

Read Byte:

1 7 1 1 8 1 8 1 1 8 1 1

| S | Target Address | Wr | A | Command Code | S | Target Address | Rd | A | Data Byte | A | P |

Read Byte with PEC:

1 7 1 1 8 1 8 1 1 8 1 1

| S | Target Address | Wr | A | Command Code | S | Target Address | Rd | A | Data Byte | A | P | ...

8 1 1

| PEC | A | P |

Read Word:

1 7 1 1 8 1 8 1 1 8 1 1

| S | Target Address | Wr | A | Command Code | S | Target Address | Rd | A | Data Byte Low | A | P | ...

8 1 1

| Data Byte High | A | P |

Read Word with PEC:

1 7 1 1 8 1 8 1 1 8 1 1

| S | Target Address | Wr | A | Command Code | S | Target Address | Rd | A | Data Byte Low | A | P | ...

8 1 1 8 1 1

| Data Byte High | A | P | PEC | A | P |

where: 
    S = Start bit
    Wr = Read bit (0)
    Rd = Read bit (1)
    Target Adddress = SMBus address for target
    Command Code = Command byte sent to target
    Data Byte = data sent to target
    A = Acknowledge from target
    PEC = Optional Packet Error Code
    P = Stop bit

~~~~~~~~

Parameters
smbusPointer to SMBus structure
targetAddrTarget address
commandCommand byte for target
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::eState, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.

§ SMBus_controllerWriteByteWord()

int8_t SMBus_controllerWriteByteWord ( 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 target.

SMBus Write ByteWord command protocol
Write Byte:
1 7 1 1 8 1 8 1 1
---------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Data Byte | A | P |
---------------------------------------------------------------------
Write Byte with PEC:
1 7 1 1 8 1 8 1 8 1 1
-------------------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Data Byte | A | PEC | A | P |
-------------------------------------------------------------------------------
Write Word:
1 7 1 1 8 1 8 1 8 1 1
----------------------------------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | P |
----------------------------------------------------------------------------------------------
Write Word with PEC:
1 7 1 1 8 1 8 1 8 1 8 1 1
--------------------------------------------------------------------------------------------------------
| S | Target Address | Wr | A | Command Code | A | Data Byte Low | A | Data Byte High | A | PEC | A | P |
--------------------------------------------------------------------------------------------------------
where:
S = Start bit
Wr = Write bit (0)
Target Adddress = SMBus address for target
Command Code = Command byte sent to target
Data Byte = data sent to target
A = Acknowledge from target
PEC = Optional Packet Error Code
P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrTarget address
commandCommand byte for target
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::eState, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.

§ SMBus_controllerQuickCommand()

int8_t SMBus_controllerQuickCommand ( 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.

SMBus Quick Commmand Protocol:
1 7 1 1 1
-------------------------------------
| S | Target Address | Rd/Wr | A | P |
-------------------------------------
where:
S = Start bit
Rd/Wr = Read or Write bit
Target Adddress = SMBus address for target
A = Acknowledge from target
P = Stop bit
Parameters
smbusPointer to SMBus structure
targetAddrTarget 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::eState, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TXQuickCMD, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.

§ SMBus_controllerWaitUntilDone()

int8_t SMBus_controllerWaitUntilDone ( 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::eState, SMBus::nwk, SMBus_NwkState_Idle, SMBUS_RET_ERROR, and SMBUS_RET_OK.

© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale