I am using Attiny1616 with Microchip Studio.
I want to store the float type results obtained from the calculation of the code in FLASH memory.
I have looked into PROGMEM, but PROGMEM does not support the float data type.
So I tried to convert the float type result to char type data using snprintf or dtostrf and save it, but it did not work.
This is my C code.
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
const char test[] PROGMEM = "Hello, world!";
char buf[5] = "";
float cal_result = 10.83;
//dtostrf(cal_result, 5, 2, buf);
snprintf(buf, 6, "%f", cal_result);
const char out[5] PROGMEM = {buf[0],buf[1],buf[2],buf[3],buf[4]};
while(1){
}
}
Thank you in advance.
What you want to do is not possible with
PROGMEM.PROGMEMis a compiler directive that prevent to useRAMto store a constant value. Instead the program will read it directly from the flash each time it need it (I ignore optimizations here)See 6.2 memory map on datasheet
0x3800 – 0x3FFFrangePROGMEMconstant value will stored in0x8000 – 0xBFFFrangeIf you want to store data computed during the program is running, you will have to use: