Why does I2C Expander reply with NAK when master sends a byte?

Thread Starter

naseeam

Joined Jan 4, 2017
80
NXP LPC11E68JBD48E Microcontroller I2C1 is Master. I2C1 is in chapter 13. I2C1 is in Master Transmitter Mode.
http://www.mouser.com/ds/2/302/UM10732-315822.pdf

NXP PCAL6416A I2C 16-bit I/O Expander is Slave. https://www.nxp.com/docs/en/data-sheet/PCAL6416A.pdf

I2C1 Block in Microcontroller is initialized successfully.

Step 1. I2C1 block is in master transmitter mode because I2C control Register STA bit is set to 1. See attached step1_Master_Transmitter_Mode.png file.

Step 2. Microcontroller I2C1 block transmits START bit. After the START bit is transmitted, the Serial Interrupt(SI) bit in I2C Control Register is set and
and STAT register in microcontroller I2C1 block contains status of 0x08. See attached filename step2_start_bit_sent.png

step 3. The status 0x08 is used to vector to a state service routine. This routine loads the slave address and Write bit to the DAT register.
See attached filename step3_status_0x08_state_handler.png

step 4. Slave address and Write bit has been transmitted and negative acknowledgement(NAK) is received from slave. The STAT register has status of 0x20 and microcontroller fires interrupt on this status value. See attached step4a_NAK_from_slave.png file and step4b_NAK_handler.png

This problem occurs the very first time Master tries to communicate with slave.
The previous hardware works fine with this microcontroller and NXP PCA6408AHKX I2C 8-bit Expander chip. When this byte is written to I2C register, ACK is received.

New hardware is same as previous hardware except 16-bit I/O expander instead of 8-bit.

What might be the problem? Is it hardware or software? What are usually reasons for NACK in I2C communication?
 

Attachments

BobaMosfet

Joined Jul 1, 2009
2,123
@naseeam
You need an oscilloscope. Looking at bit indicators is much harder than seeing wave-forms. However, hopefully, this will help.

On the 9th clock cycle, Master releases the SDA, so that the slave can pull it low to indicate an ACK. If the slave does not, it is considered a NACK (likely SCL is low, and SDA is high). If you get a NACK after sending an address, it means either:
  1. No slave responded, or
  2. slave is confused by what it received, busy processing, or is waiting for more data

You can stop, restart, and try again. Make sure your passing an address correctly- perhaps this 16-bit expander has a different address?
 

Thread Starter

naseeam

Joined Jan 4, 2017
80
The byte I'm sending is 0x42. Seven most significant bits are slave address and least significant bit is write direction bit. Please see attached filename byte_sent.png

What is the best way to find root cause of this problem?
 

Attachments

BobaMosfet

Joined Jul 1, 2009
2,123
@naseeam Re-read my previous answer. If you don't get an ACK on the 9th clock cycle, it means the slave doesn't know what to do. Either it didn't understand the address, it didn't get enough bits, got too many, or didn't recognize it was addressed at all.

An oscilloscope is the only way you can trap the actual data train and see exactly what is going on.

Make sure your I2C/TWI speed is correct. If anything, because it doesn't seem to be responding to the address, slow it down, and try again. The only thing you're trying to achieve right now is to get it to ACK at it's address, to show it's responding to its address. Make sure it's address is 2 (that's what you're saying it is). If it's address is 0, then trying to reach it with 2 won't help. Assume nothing. Test each simple thing first, and work towards complexity.
 

Thread Starter

naseeam

Joined Jan 4, 2017
80
Attached are scope screenshots for existing hardware and new hardware.

With existing hardware, slave sends an ACK.

With new hardware, after START condition is transmitted, master fires an interrupt to inform software that START bit has been transmitted but I don't see it on SDA line. I have trigger set on STRAT bit. What might be the problem?
Some inputs in the I2C expander chip are floating. Is this preventing the START bit to appear on the SDA line?
From I2C expander datasheet: "External resistors are required for inputs (on P Port) that may float. Also, internal pull-up or pull-down may be used to eliminate the need for external components."
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,787
According to your scope shots, it's not getting a NAK, you don't have any bus activity at all. You should at least get the Start condition and 9 clocks before it quits. Thoughts:

The trigger level on the blank screen is pretty close to the 3V3 signals on the good one. Maybe lower that a bit to be sure the scope is triggering. The <10Hz filter is OK for triggering?

Trigger the scope in the one-shot mode to trap just the Start and address.

Be sure SDA and SCL are pulled up on the bus. Use a 'Force Trigger' on the scope to see what those levels are. If the master senses that the bus is not idle, it will not send the Start condition - assuming it follows the I2C spec.

Just thinking out loud..
Good luck.
 
Top