CYPD3171-24LQXQ_pb: add I2C master write in soft timer callback, but occurring reboot

Announcements

Live Webinar: USB-C adoption. Simple & Cost-efficient solutions | April 18th @9am or 5pm CEST. Register now !

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

cross mob
HuEd_3452391
Level 3
Level 3
25 sign-ins First like received 10 sign-ins

Hello,

1. In main.c

----

    timer_start (0, VBUS_MONITOR_TIMER_ID, VBUS_MONITOR_TIMER_PERIOD, vbus_monitor_timer_cb);

    while (1)

    {

...

    }

----

2. soft timer callback below in main.c as well

----

void vbus_monitor_timer_cb (

    uint8_t port,

    timer_id_t id)

{

    (void)port;

    (void)id;

    I2CM_I2CMasterWriteBuf(....)

    timer_start (0, VBUS_MONITOR_TIMER_ID, VBUS_MONITOR_TIMER_PERIOD, vbus_monitor_timer_cb);

}

--

add I2C write in soft timer callback, but occurring reboot.

My question is can not use the I2C master write in soft timer callback?

Thanks

0 Likes
1 Solution
Pranava_YN
Moderator
Moderator
Moderator
100 likes received 500 replies posted 250 solutions authored

Hi,

Can you please mention the exact return code I2CM_I2CMasterStatus() is returning when its struck in while loop?

Can you also try disabling the watchdog timer reset in config.h

/* Enable watchdog hardware reset for CPU lock-up recovery */

#define WATCHDOG_HARDWARE_RESET_ENABLE              (0u)

/* Disable CCG device reset on error (watchdog expiry or hard fault). */

#define RESET_ON_ERROR_ENABLE                       (0u)

Above are the 2 Macros in config.h you need to disable.

Also instead of Buffer based APIs you can try using (throughout the project) byte level APIs. You can refer to Component datasheet for example implementation.

Regards,

Pranava

Best regards,
Pranava

View solution in original post

13 Replies
Pranava_YN
Moderator
Moderator
Moderator
100 likes received 500 replies posted 250 solutions authored

Hi,

Using I2C write inside a timer callback should not be an issue.

Can you please confirm whether the VBUS_MONITOR_TIMER_ID you have defined lies within 0xE0 to 0xFF.

Regards,

Pranava

Best regards,
Pranava
0 Likes

I think the root cause is that  I add a "while loop" code after I2CM_I2CMasterWriteBuf, so the Watch dog timer trigger the reboot?

--

  I2CM_I2CMasterWriteBuf(....)

   while (0u == (I2CM_I2CMasterStatus() & I2CM_I2C_MSTAT_WR_CMPLT))

   {

        /* Waits until master completes write transfer */

   }

--

Any way to avoid the reboot? Please advise, thanks

Best Regards

0 Likes

Hi,

Can you please use below code so that we can confirm I2CMasterWriteBuf() function is successful and the code is not stuck in "while loop" triggering reset,

if(I2CM_I2C_MSTR_NO_ERROR == I2CM_I2CMasterWriteBuf(....))

{

     while (0u == (I2CM_I2CMasterStatus() & I2CM_I2C_MSTAT_WR_CMPLT))

        {

            /* Wait */

        }

}

Regards,

Pranava

Best regards,
Pranava
0 Likes

Hello Pranava,

Thanks for your help

I2CMasterWriteBuf() function is successful

0 Likes

Then will enter the while(1) check. The reboot problem was still occurring. Please kindly help with looking into it.

Thanks.

Best Regards

Huang

0 Likes

Hi,

Looks like the I2C write is not getting completed successfully, can you please confirm if the slave device is ACKing the transfers?

Can you please provide logic analyzer traces of I2C lines?

Regards,

Pranava

Best regards,
Pranava
0 Likes

Hello

Thanks your help.

I Upload the code on Google drive: https://drive.google.com/file/d/1sjhMeJPofRGiAFgK4ndHmi0WjQZQyAAw/view?usp=sharing

1.

and if has line:519 in main.c    while (0u == (I2CM_I2CMasterStatus() & I2CM_I2C_MSTAT_WR_CMPLT))

the waveform below, the CYPD3171 Reboot

reboot_issue.jpg

2. if I  only mark line:519         //while (0u == (I2CM_I2CMasterStatus() & I2CM_I2C_MSTAT_WR_CMPLT))

no_reboot.jpg

The CYPD3171 will not reboot, but the i2c reg_address and date is wrong. Becasue I set the uint8_t buffer[2]={0x05,0x14};  at line 515.

Please help to look into it.

Thanks

Best Regards

Huang

0 Likes

Hi,

Can you please add

(void) I2CM_I2CMasterClearStatus(); before I2CM_I2CMasterWriteBuf() call.

if you still receive errors in data, you can add

I2CM_I2CMasterClearWriteBuf() before I2CM_I2CMasterWriteBuf() as well.

Regards,

Pranava

Best regards,
Pranava
0 Likes

Hello,

I add the (void) I2CM_I2CMasterClearStatus(); before I2CM_I2CMasterWriteBuf() call. But it still happen the reboot phenomenon m.  the LA Waveform same as I provide before.

Thank you very much

Best Regards

Huang

0 Likes
Pranava_YN
Moderator
Moderator
Moderator
100 likes received 500 replies posted 250 solutions authored

Hi,

Can you please mention the exact return code I2CM_I2CMasterStatus() is returning when its struck in while loop?

Can you also try disabling the watchdog timer reset in config.h

/* Enable watchdog hardware reset for CPU lock-up recovery */

#define WATCHDOG_HARDWARE_RESET_ENABLE              (0u)

/* Disable CCG device reset on error (watchdog expiry or hard fault). */

#define RESET_ON_ERROR_ENABLE                       (0u)

Above are the 2 Macros in config.h you need to disable.

Also instead of Buffer based APIs you can try using (throughout the project) byte level APIs. You can refer to Component datasheet for example implementation.

Regards,

Pranava

Best regards,
Pranava

Hello,

its struck in while loop

I2CM_I2CMasterStatus() always be 0x04 in while loop, the problem only on soft timer.

Thank you very much

0 Likes

Hi,

PranavaY_81 wrote:

Hi,

Can you please mention the exact return code I2CM_I2CMasterStatus() is returning when its struck in while loop?

Can you also try disabling the watchdog timer reset in config.h

/* Enable watchdog hardware reset for CPU lock-up recovery */

#define WATCHDOG_HARDWARE_RESET_ENABLE              (0u)

/* Disable CCG device reset on error (watchdog expiry or hard fault). */

#define RESET_ON_ERROR_ENABLE                       (0u)

Above are the 2 Macros in config.h you need to disable.

Also instead of Buffer based APIs you can try using (throughout the project) byte level APIs. You can refer to Component datasheet for example implementation.

Regards,

Pranava

Can you please try the other suggestions and provide us the I2C log for the same?

Regards

Pranava

Best regards,
Pranava
0 Likes

Hello,

I don't want to close WDT, so I try the byte level API.

Byte level API works good, no see any error and reboot phenomenon. So I think the Buffer base API has bug while applying in the Soft timer.Thanks

0 Likes