LPC54628 I2C polling master example code not quite right.

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

LPC54628 I2C polling master example code not quite right.

1,593 Views
walkingthrough
Contributor II

Does anyone look at the examples and wonder what's going on?

Would it be too hard to ask for working examples?  I know, they're "examples".  But this one is a lulu.  It couldn't ever have worked, not as is.  Maybe this is one of their training examples where students are asked "to find the bugs" and answers deliberately aren't incorporated.

The block of code below is from i2c_polling_b2b_transfer_master.c.  Take a look at the usage of I2C_MasterWriteBlocking(); the two lines are marked with "<==HERE".  In the first instance, the address of uint8_t deviceAddress is passed.  In the second instance, the address of the data buffer to transmit is passed.  The compiler is told to expect a const void * so the compiler doesn't "squeak".

I had one job: to get FLEXComm8 talking to a resistive touch screen controller via i2c.  By the next morning.  Because of the time constraint, my thought was to use an example and build from that.

NXP + Murphy paid a visit to the SDK creators: the example doesn't work.  Looks like a cut-and-paste from somewhere else.  Now I'm on the market, looking for work..

I can't recommend NXP products.  Not any more.  I can't afford the time to investigate boobytraps.  Guys, time-to-market is ever decreasing.  Please understand that your customers aren't supposed to be beta test sites, not for stuff like this.

Looking for work in the Eastern Massachusetts area...

============================================================================

/* Send master blocking data to slave */
if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
{

   /* subAddress = 0x01, data = g_master_txBuff - write to slave.
       start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
   reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, &deviceAddress, 1, kI2C_TransferNoStopFlag);   <== HERE
   if (reVal != kStatus_Success)
   {
   return -1;
   }
   reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_txBuff, I2C_DATA_LENGTH, 0);            <== HERE
   if (reVal != kStatus_Success)
   {
       return -1;
   }

   reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);

Labels (1)
0 Kudos
3 Replies

1,224 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

If you are checking with the latest version of MCUXpresso SDK for LPCXpresso54628?

The latest version is V2.4.1

pastedImage_1.png

I don't find your mentioned code issue at <i2c_polling_b2b_transfer_master.c> file:

pastedImage_2.png


Have a great day,
Mike

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

0 Kudos

1,224 Views
walkingthrough
Contributor II

SDK 2.4.1 is what sourced the i2c example I was upset at last week.  Also dated 2018-06-18.

On the left side of MCUXpresso IDE see the "Create or Import a project".  Select "Import SDK example(s)..."

I have only one SDK installed, that for the 54628.  I left-click the image to select the board then left-click "Next".

There are a number of examples listed in the lower half-pane.  Open "driver_examples" and select "i2c".

The fifth example is "i2c_polling_b2b_transfer_master" and so I select that by setting the checkbox.  To avoid a project collision, I change the prefix to "BOARD_" (that's at top left).  Then click Finish.

The IDE runs... and I now have a project named "BOARD_i2c_polling_b2b_transfer_master".

Open the project then open the source folder.  There is "i2c_polling_b2b_transfer_master.c"

Open "i2c_polling_b2b_transfer_master.c" and scroll down to line 131.

First, what does this program do?  It sends a block of data, receives a block of data, compares the two, and hangs at the while-loop at line 200.

Okay.  Line 131 contains the call to I2C_MasterStart.().  Hm.  See below.

Lines 135 and 140 contain the calls to I2C_MasterWriteBlocking.  I believe Line 135 calls the wrong function... because deviceAddress contains the i2c address of the slave and &deviceAddress is the address of a memory location containing the slave's address.

But the documentation (you can see it via hovering the cursor) says that the second argument is a pointer to the data to be transferred.

Line 140 passes supplies the address of the buffer to be transmitted.  That's correct.

What is Line 131 doing?  Line 131 takes the I2C reference, something called "I2C_MASTER_SLAVE_ADDR_7BIT", and the last argument is kI2C_Write.  I2C_MASTER_SLAVE_ADDR_7BIT is a symbol with value 0x7EU.  I thought that address reserved.for future purpose.

Before my end, I did get an I2C transfer running.  I'm writing this from memory.. but I do remember that an attached oscilloscope showed the I2C bus handshake between master and slave.

   I2C_MasterStart(EXAMPLE_I2C_MASTER, deviceAddress, kI2C_Write);      // Set slave address.

   I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_txBuff, I2C_DATA_LENGTH, 0);  // Start transaction.

   I2C_MasterStop(EXAMPLE_I2C_MASTER);      // End transaction.

All three functions are in fsl_i2c.h .

All this was with SDK 2.4.1 dated 2018-06-18.  That's what was available Monday, October 15th.

==============

My apologies to the user community for the tone of my writing last week.  I'd used similar-named routines on other devices, discounted that because, well, this is an NXP device, and went with what was in front of me rather than dig into the provided code.  A "tight-schedule-hope-it-works" situation.

Mark

0 Kudos

1,224 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Mark,

I followed your posted steps and import the i2c_polling_b2b_transfer_master project.

I don't find there with any strange code at <i2c_polling_b2b_transfer_master.c> file:

pastedImage_1.png

The actual I2C master will transfer below signals:

start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop

line131: I2C master transfer start + slaveaddress(w)

line135: I2C master transfer subAddress

line140: I2C master transfer length of data buffer + data buffer + stop

Please check below I2C signal for the detailed info:

pastedImage_2.png

The MCUXpresso SDK server was maintained last week, I am not sure if that cause the problem code generated.

Wish it helps.


Have a great day,
Mike

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

0 Kudos