2
\$\begingroup\$

address output

I am writing code for an ATtiny25 to interface with a proximity sensor VCNL4200 (slave address 0x51).

The picture you are seeing is 9 clock signals signifying initial slave address along with write bit and NACK. I can't seem to get the response ACK bit I want.

Unfortunately, the ATtiny25 uses USI and has no hardware I2C implementation. I am using the USI_TWI_MASTER.h library provided by Microchip. I feel as though my timings are well within reason as per the datasheet provided by the sensor. I am running in standard, not fast mode I2C.

  1. If someone has run into issues regarding using this library and has advice on how to proceed I would greatly appreciate it.

  2. If you have any comments about the waveforms or issues regarding it I will gladly listen.

  3. There is a snippet of code in the TWI master library:

unsigned char tempUSISR_8bit = 
(1 << USISIF) | 
(1 << USIOIF) | 
(1 << USIPF) | 
(1 << USIDC) | // Prepare register value to: Clear flags, and
(0x0 << USICNT0); // set USI to shift 8 bits i.e. count 16 clock edges.
unsigned char tempUSISR_1bit = 
(1 << USISIF) | 
(1 << USIOIF) | 
(1 << USIPF) | 
(1 << USIDC) | // Prepare register value to: Clear flags, and
(0xE << USICNT0); // set USI to shift 1 bit i.e. count 2 clock edges.

where the USISR interrupts are cleared by writing 1 to them. I am confused as to why this is the case despite reading the datasheet. If someone could also help me clarify what is going on in these two statements aside from setting the counter I would be grateful.

UPDATE Hi everyone, thank you for the responses,

I've managed to get hold of a eval module with the sensor on it and hooked it up directly to my Attiny. I was successfully able to get Ack bits from this janky setup. Unfortunately the same cannot be said with the sensor directly on my PCB. I will update accordingly.

\$\endgroup\$
9
  • \$\begingroup\$ Have you bought your VCNL4200 from a proper distributor? I ask because it's a rather expensive chip with no markings, and that's an invitation to forgers. Have you checked it with another I²C master? \$\endgroup\$
    – Janka
    Oct 25, 2022 at 9:11
  • 4
    \$\begingroup\$ What pull-up resistances you have? Are you sure the pins are not push pull outputs, the rising edge looks too sharp? Are SDA and SCL connected the correct way around? \$\endgroup\$
    – Justme
    Oct 25, 2022 at 10:19
  • \$\begingroup\$ I can't see 51 encoded in your picture. \$\endgroup\$
    – Andy aka
    Oct 25, 2022 at 11:17
  • 1
    \$\begingroup\$ @Andyaka I see 1010001W \$\endgroup\$
    – brhans
    Oct 25, 2022 at 11:55
  • 1
    \$\begingroup\$ The I2C slave address is normally 7 bits (unless it's 10 bits). \$\endgroup\$
    – brhans
    Oct 25, 2022 at 12:08

1 Answer 1

2
\$\begingroup\$

Here is a working waveform from a VCNL4200. I put a resistor in series (about 1/10 PU value) with the SDA signal from the slave so I can know for sure the direction of the signal. MCU is MSP430FR5994 so my S/W won't help you.

enter image description here

As justme said, your rising edges are too sharp, your outputs may not be in open-collector/drain mode.

The other difference is the SCL idle mode before the cycle starts. I don't know for sure if this is a violation, but the SCL idle state is normally high. If nothing else, an idle low state will waste power for no reason.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.