NucleoF411RE Communication via usb does not work stable

I have 1 Nucleo f411re device. I write my codes with mbed.os and upload the resulting bin file to my card. However, my card sometimes reads this file and sometimes it does not. I have a stable operation problem. I am sure that I wrote the codes correctly, because I ran it many times and the system I wanted came true.Every time I load the bin file, sometimes it works, sometimes it doesn’t. It doesn’t work most of the time, it works occasionally. I need to do a project and therefore I need a determined work.

All my drivers are the latest. I am using windows 10.

Hello,

what tool are you using? - Overview - Build tools | Mbed OS 6 Documentation
What version of MbedOS do you use?
Simple It doesn’t work is not enought. What should your code do?
How does it manifest itself? Some crash report in console or something else?

BR, Jan

I am using online mbed.os compiler.
Screenshot_1

This is an RFID application. When the correct card is scanned, the led lights up, when the wrong card is scanned, the led turns off. Simple application. I am also sharing the codes. I ran this app many times, it worked the way I wanted. My big problem here is that it doesn’t work STABLE. For example, I compile the code. Then the bin file is created automatically. I am uploading this code to the card. Then while waiting for the code to run, sometimes it works, sometimes it doesn’t. In other words, when the RFID card is scanned, it does not respond. I reload the code, still not responding. It goes on like this. Then it works, but the next time it breaks again. It works unstable.

#include “mbed.h”
#include “MFRC522.h”

#define SPI_MOSI D11
#define SPI_MISO D12
#define SPI_SCLK D13
#define SPI_CS D10

#define MF_RESET D8

MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);
DigitalOut led(PC_3);

int main(void)
{
RfChip.PCD_Init();
while(true)
{
if(!RfChip.PICC_IsNewCardPresent())
{
wait_ms(50);
continue;
}
if(!RfChip.PICC_ReadCardSerial())
{
wait_ms(50);
continue;
}
printf(“Kart numarasi: “);
for(uint8_t i = 0 ; i < RfChip.uid.size; i++)
{
printf(” %X”, RfChip.uid.uidByte[i]);
}
printf("\n\r");
uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
printf(“PICC Type: %s \n\r”, RfChip.PICC_GetTypeName(piccType));
wait_ms(50);
if(RfChip.uid.uidByte[0]==0x35 &&RfChip.uid.uidByte[1]==0xB6 && RfChip.uid.uidByte[2]==0x2E && RfChip.uid.uidByte[3]==0x50)
{
led = 1;
}
else
{
led = 0;
}
}
}

I would also like to point out that this happens in any other application as well. Sometimes I can see the result I expect, sometimes I can’t.

I do not want to say, it is impossible, but it seems like it sticks in a while loop during init function call.
Did you try to debug it like that?

#include "mbed.h"
#include "MFRC522.h"

#define SPI_MOSI D11
#define SPI_MISO D12
#define SPI_SCLK D13
#define SPI_CS D10

#define MF_RESET D8

int main(void)
{
	printf("RFID start\n");
	MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);
	DigitalOut led(PC_3);
	RfChip.PCD_Init();
	printf("RFID init done!\n");
	while(true)
	{
		if(!RfChip.PICC_IsNewCardPresent())
		{
			wait_ms(50);
			continue;
		}
		if(!RfChip.PICC_ReadCardSerial())
		{
			wait_ms(50);
			continue;
		}
		printf("Kart numarasi: ");
		for(uint8_t i = 0 ; i < RfChip.uid.size; i++)
		{
			printf(" %X", RfChip.uid.uidByte[i]);
		}
		printf("\n\r");
		uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
		printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
		wait_ms(50);
		if(RfChip.uid.uidByte[0]==0x35 &&RfChip.uid.uidByte[1]==0xB6 && RfChip.uid.uidByte[2]==0x2E && RfChip.uid.uidByte[3]==0x50)
		{
			led = 1;
		}
		else
		{
			led = 0;
		}
	}
}

That will tell you the program is really executed or not.
BR, Jan

Ok, that is also strange, but that looks like a bad contact somewhere. Did you try to change USB cable?

BR, Jan

First of all, thank you for your care and I am greatful to you. I don’t think there is a problem with the USB cable, because with the same cable I can control Arduino NANO without any problem. I tried it on different USB points. However, I came across the same unstable work again. I’m trying to see my work on the serial monitor. However, when the card does not react, nothing appears on the serial monitor. I’ve searched for the reason but can’t find anything.

This must be a joke. I tried the code you sent, thank you for that also. I guess when I remove the RFID module while the circuit is running, or when there is no contact, I have to throw the code again. So it works again. It’s a strange situation. I will continue to observe in other applications.