Page 1 of 1

SI2C Module and a CAT5171 Digipot Problem

Posted: Thu Apr 28, 2016 6:19 pm
by Jon Chandler
I'm using an On Semiconductor CAT5171 digipot with the SI2C module and having a strange problem. When I red back the values I write to it, the returned value is half of the value I set. I don't know if the set value is incorrect, or the returned value.

I'm reading the register just as a way to determine if this auxiliary board is in the circuit.

The code is pretty simple and there's little chance for error, so I'm wondering if it's a problem is the SI2C module.

I use this code to set the value. Val2 is the level it's set to. Val1 is the instruction byte, which turns the chip on and DOES NOT set the wiper to mid-range.

Code: Select all

    'setting the CAT5171
    Val1 = %00000000 'not mid-scale, normal ops
    I2CDevice = 88
    SI2C.Start
    SI2C.WriteByte(I2CDevice)
    SI2C.Acknowledge(I2C_ACKNOWLEDGE)
    SI2C.WriteByte(Val1)
    SI2C.Acknowledge(I2C_ACKNOWLEDGE)
    SI2C.WriteByte(Val2)
    SI2C.Acknowledge(I2C_ACKNOWLEDGE)
    SI2C.Stop
 

And here's the subroutine where I'm reading the value back.

Code: Select all




Sub DetectBoard() 
    dim ReturnedValue as byte  
    I2CDevice = 88 +1 ' for read
    SI2C.Start
    SI2C.WriteByte(I2CDevice)
    SI2C.Acknowledge(I2C_ACKNOWLEDGE)
    ReturnedValue = SI2C.ReadByte
    SI2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
    
    SI2C.Stop
    If ReturnedValue = 0 Then
            Audio_Board_Installed = false
        Else
            Audio_Board_Installed = true
    End If    
    UART.Write (DecToStr(returnedvalue), 13, 10)

End Sub

There's not much to go wrong here.

The micro is an 18F25K22.

Any suggestions?

Re: SI2C Module and a CAT5171 Digipot Problem

Posted: Thu Apr 28, 2016 8:44 pm
by Jerry Messina
When you're writing the ACK should come from the slave device, so I think those routines should look like:

Code: Select all

 'setting the CAT5171
    Val1 = %00000000 'not mid-scale, normal ops
    I2CDevice = 88
    SI2C.Start
    SI2C.WriteByte(I2CDevice)
    SI2C.WriteByte(Val1)
    SI2C.WriteByte(Val2)
    SI2C.Stop
 

Sub DetectBoard() 
    dim ReturnedValue as byte  
    I2CDevice = 88 +1 ' for read
    SI2C.Start
    SI2C.WriteByte(I2CDevice)
    ReturnedValue = SI2C.ReadByte
    SI2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
    SI2C.Stop

    If ReturnedValue = 0 Then
        Audio_Board_Installed = false
    Else
        Audio_Board_Installed = true
    End If    
    UART.Write (DecToStr(returnedvalue), 13, 10)
End Sub
Another way to do this is to just send the device address and see if it ACKs.
If you get an ACK then there's something at that I2C address

Code: Select all

I2CDevice = 88
SI2C.Start()
SI2C.WriteByte(I2CDevice)
SI2C.Stop()

// NotAcknowledged is the SDA line, so 0=ACK and 1=NACK
// (you could just test the boolean for true/false)
if (bit(SI2C.NotAcknowledged) = 0) then
    // device present
else
    // device not present
endif

Re: SI2C Module and a CAT5171 Digipot Problem

Posted: Thu Apr 28, 2016 9:27 pm
by Jon Chandler
Thank you sir,

Once again you saved the day!

Jon