FRDM-K22F communicating with FXO8700

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

FRDM-K22F communicating with FXO8700

Jump to solution
641 Views
errorek123
Contributor III

Hi,

I'm trying to communicate with FXO8700CQ sensor on my frdm-k22f board and it has been succesful but it wasn't untill i looked into someones code and added I2C_wait function .I'm not really sure why do i have to wait for interrupt flag and clear it even when i'm not using I2C interrupts(it's not working without it). I thought RXAK bit would be better as a "hold" condition to make sure we got response from slave device. Could u please clear that out?

static inline void I2C_wait(I2C_Type *base)
{
            while((base->S & I2C_S_IICIF_MASK)==0);

            base->S |= I2C_S_IICIF_MASK;
}

0 Kudos
1 Solution
537 Views
mjbcswitzerland
Specialist V

Hi Brian

The blocking I2C functions need to use the status register (which can generate interrupts) even when interrupts are not used. Also, so that the flags correctly respect the state of the I2C controller they need to be reset for subsequent transfers.

Non-blocking FRDM-K22F accelerometer binary reference: http://www.utasker.com/kinetis/FRDM-K22F.html
I2C operation in the uTasker project (including I2C device simulation): http://www.utasker.com/docs/uTasker/uTasker_I2C.pdf
Open Source version freely available at https://github.com/uTasker/uTasker-Kinetis

Regards

Mark

Complete Kinetis solutions for professional developments, training and support: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html

View solution in original post

0 Kudos
4 Replies
537 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Brian Smith,

    What's the code you are referring now?

   You can refer to our FRDM-K22F120M sdk code which can be downloaded from this link:

   Welcome | MCUXpresso SDK Builder 

   Choose the FRDM-K22F120M board, generate the code and download it.

   Now, you can find the FXO8700 code from this folder:

  SDK_2.5.0_FRDM-K22F\boards\frdmk22f\driver_examples\i2c\read_accel_value_transfer

  I didn't find the I2C_wait API which you have mentioned.

   I think, if you didn't enable the interrupt, you don't need to clear I2C_S_IICIF_MASK bit.

   You can check our latest SDK code for FRDM-K22F120M.

Wish it helps you!

If you still have question about it, please kindly let me know.


Have a great day,
Kerry

 

-------------------------------------------------------------------------------
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
537 Views
errorek123
Contributor III

Here is my main write function:

void I2C_writeRegister(I2C_Type *base, uint8_t slaveAddress,uint8_t registeraddress,uint8_t data)
{
         I2C_start(base,slaveAddress,i2c_write);
         I2C_wait(base);

         base->D = registeraddress;
         I2C_wait(base);

         base->D = data;
         I2C_wait(base);

         I2C_stop(base);
}

without I2C_wait function it's not working. I checked fsl_i2c driver in SDK and in write function there is while loop checking INT flag for every byte transfered.

/* Wait until data transfer complete. */
while (!(base->S & kI2C_IntPendingFlag))
{
}

So my question is why i have to clear interrupt flag when i'm not even using interrupt, it's a bit confusing at this point

0 Kudos
537 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Brian,

   You are right, the SDK polling code also use the IICIF.

  Please check the reference manual, it just use the IICIF to wait one byte is sent.

pastedImage_1.png

Wish it helps you!

If you still have question about it, please kindly let me know.


Have a great day,
Kerry

 

-------------------------------------------------------------------------------
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
538 Views
mjbcswitzerland
Specialist V

Hi Brian

The blocking I2C functions need to use the status register (which can generate interrupts) even when interrupts are not used. Also, so that the flags correctly respect the state of the I2C controller they need to be reset for subsequent transfers.

Non-blocking FRDM-K22F accelerometer binary reference: http://www.utasker.com/kinetis/FRDM-K22F.html
I2C operation in the uTasker project (including I2C device simulation): http://www.utasker.com/docs/uTasker/uTasker_I2C.pdf
Open Source version freely available at https://github.com/uTasker/uTasker-Kinetis

Regards

Mark

Complete Kinetis solutions for professional developments, training and support: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html

0 Kudos