I CANNOT WRITE I2Cx[D] REGISTER

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

I CANNOT WRITE I2Cx[D] REGISTER

1,913 Views
vdavi81_cefla
Contributor I

Hi,

I tryed to Write a driver in C++, to command a EEPROM connected to I2C1 port on my K22 microcontroller. 

I have a problema when a tried to write a command using I2C_MasterTransferBlocking, I'm not able to write register D (DATA) of I2C1 port, The function  I2C_MasterTransferBlocking, calls I2C_MasterStart.

When I debug I2C_MasterStart , after the following line:

base->D = (((uint32_t)address) << 1U | ((direction == kI2C_Read) ? 1U : 0U));

the register base->D is allways 0, even if the address is not 0.

I cannot understand Why?

I folowed this example:

...

...

sourceClock = I2C_MASTER_CLK_FREQ;

I2C_MasterInit(EXAMPLE_I2C_MASTER_BASEADDR, &masterConfig, sourceClock);

memset(&masterXfer, 0, sizeof(masterXfer));

/* subAddress = 0x01, data = g_master_txBuff - write to slave.
start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
uint8_t deviceAddress = 0x01U;
masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = (uint32_t)deviceAddress;
masterXfer.subaddressSize = 1;
masterXfer.data = g_master_txBuff;
masterXfer.dataSize = I2C_DATA_LENGTH;
masterXfer.flags = kI2C_TransferDefaultFlag;

I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);

PRINTF("Receive sent data from slave :");

..

 

0 Kudos
Reply
4 Replies

1,874 Views
scottm
Senior Contributor II

Hi,

I don't think you should be accessing the D register in your application code, if you're using the SDK driver for I2C.

If you're asking why the D register shows 0 when you read it in the debugger, it's because it's showing the last received byte from the I2C peripheral. It won't show what was written to the output side.

Have you checked that the EXAMPLE_I2C_MASTER_BASEADDR macro evaluates to a valid I2C base address?

Scott

0 Kudos
Reply

1,901 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello, 

I suggest review the example in the SDK using the MCUXpresso IDE. If you have doubt, please let me know.

Best regards,
Pavel

0 Kudos
Reply

1,898 Views
vdavi81_cefla
Contributor I

To write my code I used the example but I when tryed if it works I saw that base->D I always 0. 

 

0 Kudos
Reply

1,893 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

Could you give me the main.c of your project to see something please?

Best regards,
Pavel

0 Kudos
Reply