I2C libraries for MSSP1 and MSSP2

Thumbnail

Favourites: 0

Report File

I2C libraries for MSSP1 and MSSP2


File Information



Files




Some devices have 2 MSSP peripherals, allowing 2 separate I2C interfaces. The compiler only supports MSSP1 with the Hbus commands, so I have created 2 libraries for implementing I2C on both MSSP1 and MSSP2.

File "Hbus1.inc" is for support with the MSSP1 peripheral.
File "Hbus2.inc" is for support with the MSSP2 peripheral.

There are 3 demo programs, and an Isis simulation for the libraries. Also, the libraries are full of comments to explain what's happening within the code.

The commands are:

For MSSP1:
Generate an I2C Start on MSSP1
Input : None
Output : None
Notes : None

Hbus1_Start()

Generate an I2C Stop on MSSP1
Input : None
Output : None
Notes : None

Hbus1_Stop()

Generate an I2C ReStart on MSSP1
Input : None
Output : None
Notes : None

Hbus1_ReStart()

Generate an I2C Nack on MSSP1
Input : None
Output : None
Notes : None

Hbus1_Nack()

Generate an I2C Ack on MSSP1
Input : None
Output : None
Notes : None

Hbus1_Ack()

Send an I2C byte via MSSP1
Input : pByteout (SSP2BUF) holds the byte to write
Output : Bit Hbus1_Error holds 1 If failure, Else 0
Notes : None

Hbus1_Write_Byte(pByteout)

Send a slave address byte on MSSP1
Input : pSlaveAddress holds the I2C slave address
: pReadWrite holds 1 or 0 for read or write (1 = read, 0 = write)
Output : Bit Hbus1_Error holds 1 If failure, Else 0
Notes : Shifts the address 1 bit left, then sets or clears the read/write bit

Hbus1_Set_SlaveAddress(pSlaveAddress, pReadWrite)

Receive an I2C byte via MSSP1
Input : None
Output : pResult holds the byte received
Notes : None

Hbus1_Read_Byte(pResult
)

For MSSP2:


Generate an I2C Start on MSSP2
Input : None
Output : None
Notes : None

Hbus2_Start()

Generate an I2C Stop on MSSP2
Input : None
Output : None
Notes : None

Hbus2_Stop()

Generate an I2C ReStart on MSSP2
Input : None
Output : None
Notes : None

Hbus2_ReStart()

Generate an I2C Nack on MSSP2
Input : None
Output : None
Notes : None

Hbus2_Nack()

Generate an I2C Ack on MSSP2
Input : None
Output : None
Notes : None

Hbus2_Ack()

Send an I2C byte via MSSP2
Input : pByteout (SSP2BUF) holds the byte to write
Output : Bit Hbus2_Error holds 1 If failure, Else 0
Notes : None

Hbus2_Write_Byte(pByteout)

Send a slave address byte on MSSP2
Input : pSlaveAddress holds the I2C slave address
: pReadWrite holds 1 or 0 for read or write (1 = read, 0 = write)
Output : Bit Hbus2_Error holds 1 If failure, Else 0
Notes : Shifts the address 1 bit left, then sets or clears the read/write bit

Hbus2_Set_SlaveAddress(pSlaveAddress, pReadWrite)

Receive an I2C byte via MSSP2
Input : None
Output : pResult (SSP2BUF) holds the byte received
Notes : None

Hbus2_Read_Byte(pResult
)

Report File

Reason












Report Comment

Reason






Report Link

Reason