Report
1 week, 2 days ago.

M24SR Gets Stuck in Infinite Loop

Hi,

I've got a problem with the M24SR library and it's not clear to me how to get some help.

In summary, when using the library in synchronous mode there's an infinite loop and I get stuck in it occasionally.

From M24SR.cpp

M24SR::StatusTypeDef M24SR::M24SR_IO_PollI2C(void) {
 
    int status = 1;
    while (status != 0 ) {
        //send the device address and wait to recevie an ack bit
        status = dev_I2C.write(address,NULL,0);
    }
    return M24SR_SUCCESS;
}

AFAICT, the loop is necessary and sometimes it takes a few iterations to get the ACK. But, a loop like this that could potentially never end is pretty poor form.

It is easy enough to limit the number of iterations and return an error but what should the limit be and what should the error be?

All the code that calls M24SR_IO_PollI2C checks its status which seems a bit pointless at the moment.

Possibly more important is understanding what's going wrong when it gets stuck and I don't! Can anyone help? It could be that the M24SR is never going to ACK the command or it could be that the ACK was missed somehow??

Given this snafu, I wonder if anyone is using this library in production code and if not, what are they using?

Thanks, Matt

Question relating to:

Information on how to use the STM32 Nucleo board with mbed
Comment on this question

2 Answers

1 week, 1 day ago.

Hi Matt, Thanks for bringing this to our attention.

Could you please let us know what Nucleo board are you using the M24SR with?

What application are you using the M24SR library with? If you could give us a distilled program that we can use to reproduce this issue, that would be very helpful.

Also being discussed here: https://community.st.com/s/feed/0D50X00009vMRgG Thanks,

Naveen, Team mbed.

Hi Naveen,

I'm sorry to cause confusion but I've been double-posting!

I asked the same/similar question in the ST community. M24SR04 Stops Responding During Intense Activity. In that thread Rene suggests there could be a problem with the way this library is closing the I2C session. Although that doesn't explain explain why I get stuck in the loop while just sending I2C commands during the session.

While we do have some Nucleo boards and NFC shields I've been testing this using our in-house board, which is an STM32L442KC and a M24SR04-Y.

We have an NFC reader and a tag on our wireless device. The idea is that the reader can retrieve data and configuration from the device. To do this the reader writes a command into the tag's EEPROM and generates a interrupt. The MCU responds to the interrupt, forces the I2C session, reads the EEPROM and then writes the result to the EEPROM. If I repeat this process a great deal, sometimes up to several hundred times, it will eventually fail because the MCU gets stuck polling the I2C.

I haven't tried to create a cut-down example of the yet. Not least because it seems like it will be very difficult to do. I don't think it is I2C only problem so to demonstrate the problem both an MCU and reader app will be required.

Obviously the presence of a possibly infinite loop doesn't need demonstrating , it's pretty clear from code inspection. :-)

Thanks, Matt

posted by Matt Brown 12 Nov 2018
1 week ago.

-


To post an answer, please log in.