How to use LDD?

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

How to use LDD?

Jump to solution
2,357 Views
oleglavrukhin
Contributor IV

Hello, community! i am beginner for FRDM-k64F, CW 10.6 and Processor Expert. At first, i try to read registers from build-in  FXOS8700CQ via I2C and print it to console. I use CPU clock as default, then i added I2C_LDD component, configure it as MASTER with: interrupt=enable, address mode=7-bits, Target slave address init=0x1d, SDA pin=PTE25, SCL pin=PTE24, internal freq.=47.98 Mhz, Bits 0-2 =010, Bits 3-5 =100, SCL freq = 214.235 kHz, autoinit=Yes. Then i make a code as "Help on component" for reading 16 bytes from SLAVE from register address=0x00, and added a procedure, which printed in console Error code:

void print_error(uint8_t err_type)

{

  switch(err_type)

  {

  case 0x00U: printf("ALL OK \n"); break;

  case 0x07U: printf("Device is disabled \n"); break;

  case 0x01U: printf("ERR_SPEED\n"); break;

  case 0x08U: printf("The master device is busy\n"); break;

  case 0x81U: printf("Stop condition isn't possible generated on end transmission\n"); break;

  case 0x8DU: printf("ERR_PARAM_ADDRESS_TYPE -  Invalid address type\n"); break;

  case 0x89U: printf("ERR_PARAM_ADDRESS Invalid address value\n"); break;

  case 0x09U: printf("Requested value or method not available\n"); break;

  }

}

main.c:

....................

LDD_TDeviceData *My_IIC_Ptr;

LDD_TError Error;

uint8_t TX_buff[1];

uint8_t RX_buff[16];

TX_buff[0]=0;

  Error= CI2C1_MasterSendBlock(My_IIC_Ptr, (uint8_t *) TX_buff, 1, LDD_I2C_NO_SEND_STOP);// send to FXOS8700CQ register =0

  Error= CI2C1_MasterReceiveBlock(My_IIC_Ptr, (uint8_t *) RX_buff, 16, LDD_I2C_SEND_STOP);// read registers 0x00-0x0F from FXOS8700CQ 

  print_error(Error);

..............

In the DEBUG after execution "CI2C1_MasterReceiveBlock", I get "error=0x08", "The master device is busy", and input buffer RX_buff contains 0x00.

if I added in code checking  "DataReceivedFlg" and "DataTransmittedFlg" (as in "Help"), program enters an infinite loop, because it is not an event occurs (I2C2_OnMasterBlockSent or I2C2_OnMasterBlockReceived) .

my questions:

1) Do I Need added "PinSetting" component if i already added I2C_LDD ?

2) why I do not see the processing of an event in the debugger? (I2C2_OnMasterBlockSent and I2C2_OnMasterBlockReceived)?

3) if i try to use "CI2C1_SelectSlaveDevice" method for set a new slave, i get "error=0x08", "The master device is busy". Why?

PLS, HELP ME TO UNDERSTANDING HOW TO USE LDD COMPONENT CORRECRTLY !!!

later i planning to use I2S port in FRDM-K64F, but i think what I can not work with it as long as I do not understand how to properly use LDD_components in PEx.

Thanks,

Oleg

P.S. I tried to use another code for I2C, based on a macros. and it work finely....

0 Kudos
1 Solution
905 Views
BlackNight
NXP Employee
NXP Employee

I have a full example project for you (attached), but it is for KDS (Kinetis Design Studio), using Processor Expert.

As you might see, it comes with a Processor Expert component for the FXOS8700 (see Enabling/Disabling FXOS8700CQ Device Needs a Delay | MCU on Eclipse).

I'm using the I2C LDD with another driver layer (GenericI2C): don't get confused by that, as I'm using this as a compatibility layer between LDD and non-LDD layers.

More about this in A Generic I2C High Level Driver | MCU on Eclipse

I recommend that you have a look at Tutorial: Accelerating the KL25Z Freedom Board | MCU on Eclipse. This is for the KL25Z, but it uses the I2C LDD and it applies for the K64F as well.

I hope this helps,

Erich

View solution in original post

0 Kudos
6 Replies
906 Views
BlackNight
NXP Employee
NXP Employee

I have a full example project for you (attached), but it is for KDS (Kinetis Design Studio), using Processor Expert.

As you might see, it comes with a Processor Expert component for the FXOS8700 (see Enabling/Disabling FXOS8700CQ Device Needs a Delay | MCU on Eclipse).

I'm using the I2C LDD with another driver layer (GenericI2C): don't get confused by that, as I'm using this as a compatibility layer between LDD and non-LDD layers.

More about this in A Generic I2C High Level Driver | MCU on Eclipse

I recommend that you have a look at Tutorial: Accelerating the KL25Z Freedom Board | MCU on Eclipse. This is for the KL25Z, but it uses the I2C LDD and it applies for the K64F as well.

I hope this helps,

Erich

0 Kudos
905 Views
oleglavrukhin
Contributor IV

Dear Erich, building your projects return some errors: "PE_LDD_COMPONENT_BitIoLdd1_ID (and BitIoLdd2 and BitIoLdd3) undeclarated". I can't found this macro in project. where they are hidden? :smileyblush:

0 Kudos
905 Views
BlackNight
NXP Employee
NXP Employee

It is in Generated_Code/PE_Types.h of the zip file, around line 207:

#define PE_LDD_COMPONENT_BitIoLdd1_ID        0x01U
#define PE_LDD_COMPONENT_BitIoLdd2_ID        0x02U
#define PE_LDD_COMPONENT_BitIoLdd3_ID        0x03U

Erich

0 Kudos
905 Views
oleglavrukhin
Contributor IV

Dear Erich, Building Your project return new errors with #define ... and I stop work with it.

But I studied Your tutorials in "mcuoneclipse" and Understanding, what  MasterSendBlock() and MasterReceiveBlock() methods do not have the necessary flexibility, so you use Generic I2C and get the desired results.

I found  a  "FXOS8700CQ - Bare metal example project"  and make a communications with FXOS8700CQ on the my FRDM-K64F board based on I2C driver code for this project, and it work nice.

Thanks for your help and wait for new tutorial for FRDM-K64F (for example, I2S...)

Best regards, Oleg

0 Kudos
905 Views
oleglavrukhin
Contributor IV

Thanks, Erich. But  I still want to get answers to their questions 1) 2) 3)...

0 Kudos
905 Views
BlackNight
NXP Employee
NXP Employee

Hi Oleg,

1) yes, as with this the system wide muxing is done.

2) you only get these events for completed transactions. If your transaction is stuck you won't get the events

3) that is very likely due 2) above.

I recommend that you check with a logic analyzer your SDA and SCL lines.

Erich