I’am working with a custom STM32f103C8T6 board for research, it’s connected to a radio receiver module through uart and SD card module through SPI, basically, i receive a data from the receiver module and save it in the sd card and display it in serial monitor. First, I developed a code that read the data from the receiver module and display it in the serial monitor and it worked, then when i add the sd card part of the code to save the data into it I got an error “Cannot initialize RTC with LSE” (the detail error message is written below the code in this post). i have tested the full code (including the sd card part) in nucleo l432kc board (i connect the radio module and the sd card as well) and it worked just fine. Is there any solution to this problem?
PS. I used the nucleo F103RB platform when compiling in the mbed compiler
#include "mbed.h"
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
// Instantiate the SDBlockDevice by specifying the SPI pins connected to the SDCard
// socket. The PINS are:
// MOSI (Master Out Slave In)
// MISO (Master In Slave Out)
// SCLK (Serial Clock)
// CS (Chip Select)
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
FATFileSystem fs("sd", &sd);
Serial pc(USBTX, USBRX, 9600); // tx, rx
Serial device(PA_9, PA_10, 115200); // tx, rx
AnalogIn LM35(PA_0);
int i;
int z;
char buffer[1024];
float tempC,tempF,a[10],avg;
void return_error(int ret_val)
{
if (ret_val) {
printf("\n\r Failure. %d \n\r", ret_val);
while (true) {
__WFI();
}
} else {
printf("Done \n\r");
}
}
void errno_error(void *ret_val)
{
if (ret_val == NULL) {
printf("\n\r Failure: %d \n\r", errno);
while (true) {
__WFI();
}
} else {
printf("Done \n\r");
}
}
int main()
{
set_time(1639401437);
pc.format(8,SerialBase::None,1);
int error = 0;
if (0 != sd.init()) {
printf("SD Card Init Failed ! \n\r");
return -1;
}
printf("\n\rSD Card Init Success ! \n\r \n\r");
printf("SD Card Size: %llu\n\r", sd.size());
printf("SD Card Read size: %llu\n\r", sd.get_read_size());
printf("SD Card Program size: %llu\n\r", sd.get_program_size());
printf("SD Card Erase Size: %llu\n\r", sd.get_erase_size());
printf("\n\rMounting the filesystem\n\r");
error = fs.mount(&sd);
printf("Opening a new file, output.txt......");
FILE *fd = fopen("/sd/output.txt", "w+");
errno_error(fd);
printf("\n\r-----------------------------n\r");
printf("\n\rReading Sensor:\n\r");
int y = 0;
while(y <= 10000)
{
avg=0;
for(z=0;z<10;z++)
{
a[z]=LM35.read();
thread_sleep_for(.02);
}
for(z=0;z<10;z++)
{
avg=avg+(a[z]/10);
}
if(device.readable())
{
while(device.getc() != '#');
for(int i=0; i<256; i++)
{
buffer[i] = device.getc();
if(buffer[i] == '\r')
{
buffer[i] = 0;
break;
}
}
}
char buffer_time[32];
time_t seconds = time(NULL);
strftime(buffer_time, 32, "%D %T %p\n", localtime(&seconds));
tempC=(avg*3.685503686*100);
tempF=(9.0*tempC)/5.0 + 32.0;
printf("\n\rDate/Time: %s \n\r", buffer_time);
printf("Temperature: %.2f C %.2f F \n\r",tempC,tempF);
printf("Receiver: '%s' \n\r", buffer);
printf("Writing to SD Card......");
fprintf(fd, "\n\rDate/Time: %s \n\r", buffer_time);
fprintf(fd, "Temperature: %.2f C %.2f F \n\r",tempC,tempF);
fprintf(fd, "Receiver: '%s' \n\r", buffer);
printf("Done \n\r \n\r \n\r");
thread_sleep_for(1);
y++;
}
printf("\n\r-----------------------------n\r");
printf("Closing file......");
fclose(fd);
printf("Done \n\r");
printf("Unmounting File System......");
fs.unmount();
printf("Done \n\r");
printf("De-init SD Card......");
sd.deinit();
printf("Done \n\r");
}
below is the error as shown in the terminal,
++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Mess ge: Fatal Run-time error
Location: 0x800E9C1
Error Value: 0x0
Current Thread: main Id: 0x20002338 Entry: 0x800D099 StackSize: 0x1000 StackMem: 0x20000878 SP: 0x20 0174C
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=NUCLE _F103RB
-- MbedOS Error Info --
Cannot initialize RTC with LSE
here is my board schematics,