I2C Driver, SDK v2.2 not issuing device address

cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Driver, SDK v2.2 not issuing device address

489 Views
Cdn_aye
Senior Contributor I

Hi, I have read through the post "

Problem sending I2C message"

and I have a slightly different problem. The device I am talking to requires the device address to be resent (ie readdressed with the Read bit High) after the the initial write of the device address. This is not happening in the device driver.

I have:

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I2C_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate_Bps = I2C_BAUDRATE;

sourceClock = I2C_MASTER_CLK_FREQ;

I2C_MasterInit(I2C0, &masterConfig, sourceClock);

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

masterXfer.slaveAddress = 0x68;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = 0x75;
masterXfer.subaddressSize = 1;
masterXfer.data = c_buff;
masterXfer.dataSize = 1;
masterXfer.flags = kI2C_TransferNoStopFlag;

I2C_MasterTransferCreateHandle(I2C0, &g_m_handle, i2c_master_callback, NULL);

I2C_MasterTransferNonBlocking(I2C0, &g_m_handle, &masterXfer);

masterXfer.direction = kI2C_Read;
masterXfer.flags = kI2C_TransferRepeatedStartFlag;

I2C_MasterTransferNonBlocking(I2C0, &g_m_handle, &masterXfer);

/* Wait for transfer completed. */
while (!g_MasterCompletionFlag){}
g_MasterCompletionFlag = false;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%

The call back is occurring however I get no data back because I haven't issued a read with the device address. Can you tell me how to configure the driver to do this. I have attached a screen shot of a logic analyzer with a working correct driver, versus the SDK v2.2, non working driver results.

Thanks in advance

Robert

0 Kudos
3 Replies

157 Views
Cdn_aye
Senior Contributor I

Hi Visajhan

Thank you for replying.

I followed the code example from this question "Problem sending I2C message". In that example it was pointed out the the stop call back was failing because of the wrong flag being used. The recommendation was to wait on the transfer completion flag. I implemented the code exactly like this, but maybe I am misunderstanding how this should work. I thought that the read would send the slave address with the write bit as a 0, then get the ACK and send out the slave address with the read bit set as a 1, then receive an ACK and the transfer would be complete.

Can you advise me on how to set the flags or to check for the correct status so the slave address is sent prior to the read please?

Regards

Robert

0 Kudos

157 Views
visakhanc
Contributor III

Hi Robert,

I have gone through the driver and found that only a single driver call is enough to read from a location of a slave (that is 0x75 in your case) into location c_buff. Try this:

I2C_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate_Bps = I2C_BAUDRATE;

sourceClock = I2C_MASTER_CLK_FREQ;

I2C_MasterInit(I2C0, &masterConfig, sourceClock);

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

masterXfer.slaveAddress = 0x68;
masterXfer.direction = kI2C_Read;
masterXfer.subaddress = 0x75;
masterXfer.subaddressSize = 1;
masterXfer.data = c_buff;
masterXfer.dataSize = 1;
masterXfer.flags = kI2C_TransferDefaultFlag;

I2C_MasterTransferCreateHandle(I2C0, &g_m_handle, i2c_master_callback, NULL);

I2C_MasterTransferNonBlocking(I2C0, &g_m_handle, &masterXfer);

/* Wait for transfer completed. */
while (!g_MasterCompletionFlag){}
g_MasterCompletionFlag = false;

 

Regards,

Visakhan

157 Views
visakhanc
Contributor III

Hi,

After the initial write transfer, should you be waiting for transfer completion? Otherwise the driver will return kStatus_I2C_Busy on the next transfer(for read), right?

Regards,

Visakhan

0 Kudos