how to send ACK or NACK from I2c master to slave

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
jusac_3935691
Level 1
Level 1
First reply posted First question asked

hi.

Now I'm writing I2C master program referring to the following.

FM_PDL_2.0.1/example/mfs/i2c/i2c_polling/i2c_master_polling/main.c

To read some data from slave to master, the sample program is using I2c_Read().

And this function is calling Mfs_I2c_ConfigAck() to send ACK or NACK to slave.

But the description of Mfs_I2c_ConfigAck() says "Configure ACK signal sent to master", "This function is only meaningful when I2C is in slave mode". (mfs.c L.3527~)

Can I use Mfs_I2c_ConfigAck() in master program?

Why I ask this, my I2C master program (on FM0+ S6E1C) has stop in Mfs_I2c_GetStatus() loop (main.c L.272~) after reading first byte. So I doubt that NACK has not been transmitted properly.

The 1 byte looks like correct, but can't read any more.

thanks.

0 Likes
1 Solution
jusac_3935691
Level 1
Level 1
First reply posted First question asked

Sorry, this discussion will be my answer.

http://japan.cypress.com/forum/fm0-32-bit-arm-cortex-m0-microcontroller-mcu/i2c-read-hangs-mdk-pdl-2...

I'm using same (ARM) environment.

I will try a modified Mfs_I2c_ConfigAck() on the next business day.

en_result_t Mfs_I2c_ConfigAck(volatile stc_mfsn_i2c_t* pstcI2c, en_i2c_ack_t enAck)

{

   stc_mfs_i2c_ibcr_field_t stcIbcr;

   if (NULL != pstcI2c)

   {

       return ErrorInvalidParameter;

   }

  

   stcIbcr = pstcI2c->IBCR_f;

   stcIbcr.ACKE = (I2cAck == enAck) ? 1u : 0u;

   stcIbcr.ACT_SCC = 0u; /* Set SCC = 0 to avoid generating a restart */

   pstcI2c->IBCR = *((uint8_t *)(&stcIbcr));

   return Ok;

}

View solution in original post

0 Likes
1 Reply
jusac_3935691
Level 1
Level 1
First reply posted First question asked

Sorry, this discussion will be my answer.

http://japan.cypress.com/forum/fm0-32-bit-arm-cortex-m0-microcontroller-mcu/i2c-read-hangs-mdk-pdl-2...

I'm using same (ARM) environment.

I will try a modified Mfs_I2c_ConfigAck() on the next business day.

en_result_t Mfs_I2c_ConfigAck(volatile stc_mfsn_i2c_t* pstcI2c, en_i2c_ack_t enAck)

{

   stc_mfs_i2c_ibcr_field_t stcIbcr;

   if (NULL != pstcI2c)

   {

       return ErrorInvalidParameter;

   }

  

   stcIbcr = pstcI2c->IBCR_f;

   stcIbcr.ACKE = (I2cAck == enAck) ? 1u : 0u;

   stcIbcr.ACT_SCC = 0u; /* Set SCC = 0 to avoid generating a restart */

   pstcI2c->IBCR = *((uint8_t *)(&stcIbcr));

   return Ok;

}

0 Likes