I2C Problem In MK66FN2M0VLQ18

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C Problem In MK66FN2M0VLQ18

2,101 Views
durgasivakrishn
Contributor III

Hi,

I am using the MK66FN2M0VLQ18 to communicate with external EEPROM(24LC1026) with I2C interface, While interfacing with the EEPROM I a getting the NACK error what may be the problem. I am using the SDK of MK66.

With regards,

Sivakrishna

0 Kudos
10 Replies

1,906 Views
durgasivakrishn
Contributor III

Hi,

Thanks for both of you it is working fine I am able to write and read from EEPROM, But I got 2 more questions

1.) In MK66FN20VLQ18 if we configure the pin as I2C line, By default open-drain configuration is not enabled?

2.) After making the I2C pin as open-drain it is working fine(able to write and read from EEPROM) in the flash but when I run in the debug SDA pin state changed to LOW and I am getting the BUSY error what may be the problem, I tried placing the delay after pin initialization and I2C initialization but it didn't work.

With regards,

Sivakrishna

0 Kudos

1,906 Views
myke_predko
Senior Contributor III

HI Durga,

Can I ask how are you configuring the pins?  Can I also ask how do you know it's "working fine"?  

It doesn't sound like you are selecting the MUX option that is appropriate for the pins but are using the GPIO op\tion (usually MUX ALT1) when you should be using the I2C pin MUX selection.  If you're using MCUXpresso, the easiest way to correctly specify the pin mux is to use the pin configuration wizard.  

I'm not sure why you're having problems with single stepping (which is what I think you're talking about) as using the SDK driver should work while single stepping without any issues.  Are you expecting the send to happen immediately following the return from I2C_MasterTransferBlocking(I2C_EEPROM_PERIPHERAL, &Master_TX) call?  If so, you should wait until after the following delay call.  

myke

0 Kudos

1,906 Views
durgasivakrishn
Contributor III

Dear Myke,

I am considering it is working fine because I am able to see pulses on the SDA pin, But if I do debug pulses are not coming and SDA is LOW.

Debug means I am going to debug mode using Ulink2 and making it full run in this scenario it is not working and the state of the SDA pin is going to LOW. Even I do the step over the same problem is arising.

With regards,

Sivakrishna

0 Kudos

1,906 Views
myke_predko
Senior Contributor III

Hi Sivakrishna,

The code that I am using (and generated by the pin config wizard in pin_mux.c) is:

CLOCK_EnableClock(kCLOCK_PortB);
const port_pin_config_t portb2_pin37_config = {/* Internal pull-up resistor is enabled */
                                               kPORT_PullUp,
                                               /* Fast slew rate is configured */
                                               kPORT_FastSlewRate,
                                               /* Passive filter is disabled */
                                               kPORT_PassiveFilterDisable,
                                               /* Open drain is enabled */
                                               kPORT_OpenDrainEnable,
                                               /* Low drive strength is configured */
                                               kPORT_LowDriveStrength,
                                               /* Pin is configured as I2C0_SCL */
                                               kPORT_MuxAlt2,
                                               /* Pin Control Register fields [15:0] are not locked */
                                               kPORT_UnlockRegister};
/* PORTB2 (pin 37) is configured as I2C0_SCL */
  PORT_SetPinConfig(PORTB, 2U, &portb2_pin37_config);

const port_pin_config_t portb3_pin38_config = {/* Internal pull-up resistor is enabled */
                                               kPORT_PullUp,
                                               /* Fast slew rate is configured */
                                               kPORT_FastSlewRate,
                                               /* Passive filter is disabled */
                                               kPORT_PassiveFilterDisable,
                                               /* Open drain is enabled */
                                               kPORT_OpenDrainEnable,
                                               /* Low drive strength is configured */
                                               kPORT_LowDriveStrength,
                                               /* Pin is configured as I2C0_SDA */
                                               kPORT_MuxAlt2,
                                               /* Pin Control Register fields [15:0] are not locked */
                                               kPORT_UnlockRegister};
/* PORTB3 (pin 38) is configured as I2C0_SDA */
  PORT_SetPinConfig(PORTB, 3U, &portb3_pin38_config);

The only difference I see it in the two snippets is that the internal pull up resistor is enabled in the wizard provided code.  

When you say you're using "Ulink2" that's a P&E Micro debugger/programmer?  Have you reached out to them to ask about this?  

Sorry, I've seen OpenSDA strangeness when single stepping but I use the Segger J-Link Plus for my work and I definitely don't see what you are getting.  I can run at full speed or single step through I2C operations with noting that data send/clocking does not happen as you would expect).  I'm still not sure what you mean by "debug mode" - are you building the project differently to debug it?  

myke

0 Kudos

1,906 Views
durgasivakrishn
Contributor III

Dear Myke,

Thanks for the information.

With regards,

Sivakrishna

0 Kudos

1,906 Views
durgasivakrishn
Contributor III

Dear Myke,

Thanks for your response, Here I am briefing the code

/* Port B Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortB);

if use the below it is not working

|---------------------------------------- NOT WORKING ----------------------------------------|

/* PORTB2 (pin 83) is configured as I2C0_SCL */

PORT_SetPinMux(PORTB, 2U, kPORT_MuxAlt2);

/* PORTB3 (pin 84) is configured as I2C0_SDA */

PORT_SetPinMux(PORTB, 3U, kPORT_MuxAlt2);

|---------------------------------------- NOT WORKING ----------------------------------------|

|---------------------------------------- WORKING ----------------------------------------|

if use the below it is working

/* PORTB2 (pin 83) is configured as I2C0_SCL */
Pin_Config.openDrainEnable = kPORT_OpenDrainEnable;
Pin_Config.driveStrength = kPORT_LowDriveStrength;
Pin_Config.lockRegister = kPORT_UnlockRegister;
Pin_Config.mux = kPORT_MuxAlt2;
Pin_Config.pullSelect = kPORT_PullDisable;
Pin_Config.slewRate = kPORT_FastSlewRate;

PORT_SetPinConfig(PORTB,2U,&Pin_Config);

/* PORTB3 (pin 84) is configured as I2C0_SDA */
Pin_Config.openDrainEnable = kPORT_OpenDrainEnable;
Pin_Config.driveStrength = kPORT_LowDriveStrength;
Pin_Config.lockRegister = kPORT_UnlockRegister;
Pin_Config.mux = kPORT_MuxAlt2;
Pin_Config.pullSelect = kPORT_PullDisable;
Pin_Config.slewRate = kPORT_FastSlewRate;


PORT_SetPinConfig(PORTB,3U,&Pin_Config);

|---------------------------------------- WORKING ----------------------------------------|

0 Kudos

1,906 Views
durgasivakrishn
Contributor III

Dear Myke,

Thanks for your response, Here I am attaching the schematic and code. R99 is mounted and R48 is not mounted and EEPROM_WP pin is gpio making it low,

shematic.JPG

i2c_master_transfer_t Master_TX;
i2c_master_handle_t Master_TX_Handler;

uint8_t EEPROM_Tx[10]={0},EEPROM_Rx[10]={0},Return_Val=0;

#define I2C_MASTER_SLAVE_ADDR_7BIT 0xA0U

void EEPROM_Write(void)
{
Master_TX.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
Master_TX.direction = kI2C_Write;
Master_TX.subaddress = 0;
Master_TX.subaddressSize = 2;
Master_TX.data = EEPROM_Tx;
Master_TX.dataSize = 2;
Master_TX.flags = kI2C_TransferDefaultFlag;

EEPROM_Tx[0] = 0x10;
EEPROM_Tx[1] = 0x20;

while(1)
{
Master_TX.direction = kI2C_Write;
Master_TX.data = EEPROM_Tx;
I2C_MasterTransferBlocking(I2C_EEPROM_PERIPHERAL, &Master_TX);

Delay(0xFFFF);
}
}

with regards,

Sivakrishna

0 Kudos

1,906 Views
myke_predko
Senior Contributor III

Hi Sivakrishna,

I think Da Li and I are inagreement - try again with:

#define I2C_MASTER_SLAVE_ADDR_7BIT 0x50U

Let us know how you make out.

myke

0 Kudos

1,906 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Try to modify I2C_MASTER_SLAVE_ADDR_7BIT  to 0x50U

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,906 Views
myke_predko
Senior Contributor III

Any chance at getting more information?  Could you share you code and wiring?  

Regardless, the first place to look for an I2C NACK error (after checking your wiring and power) is the address that is being used to address the device.  

I just did a quick look at the datasheet for the 24LC1026 and saw that the address sent to the peripheral device is 8 bits and includes four bits for the address, two chip address (set by the pins on the chip), a block bit and a read/write bit.  It's a little hard to visualize, but the address you give the Kinetis is shifted up by one and the read/write bit added to the hardware - so to get the correct address sent out to the chip, shift the device address down by one (or divide by 2) to put out the correct address on the bus.  

If you have A1, A2 tied low and you wanted to write to block 0 of the chip, you would be sending an address of 0b10100000 (0xA0) BUT because of the read/write bit is handled in hardware and added to the address, you have to shift this down by one bit (to 0b01010000) and set address to 0x50 for the I2C hardare.  

Take a look at what you have and let us know what you find.  

myke

0 Kudos