I'm writing a program that receives a time from an RTC over TWI then writes that time into flash memory using the example from the flash FDS library. The problem I'm running into is that I receive my clock data as an array that holds values for the time ie: rx_data[0] = 13 rx_data[1] = 56. This would represent the time 13:56, but I want to store the time in a formatted char array which I create in line 14.
I want to save this entire char array to the flash memory, but the program seems to only be able to write static const char arrays to memory. So my questions are:
1.) Why can I only write static const char arrays to memory? Is there a way to store character arrays in some other format?
2.) Is there a way to convert my static char array that holds the formatted time to a static const char array? In c++ I would use something like strcpy but I'm not sure how to do this in C.
Here is my code:
void writeTime() { #define FILE_ID 0x0005 /* The ID of the file to write the records into. */ #define RECORD_KEY_1 0x5555 /* A key for the first record. */ ret_code_t rc = NULL; uint8_t* rx_data = clockTime(); //get the pointer to the array that holds the clockTime static char m_timeStart[50] = {0}; //generate a char array that holds the start time from the array snprintf(m_timeStart, sizeof(m_timeStart), "%x:%x:%x on %x/%x/%x", rx_data[2], rx_data[1], rx_data[0], rx_data[5], rx_data[4], rx_data[6]); fds_record_t record; fds_record_desc_t record_desc; // Set up record. record.file_id = FILE_ID; record.key = RECORD_KEY_1; record.data.p_data = &m_timeStart; /* The following calculation takes into account any eventual remainder of the division. */ record.data.length_words = (sizeof(m_timeStart) + 3) / 4; rc = fds_record_write(&record_desc, &record); }
Thanks!