I'm trying to write measurements from external sensor to the file (lets say 1 per second). I'm using ATMega32 and PetitFS. At this moment I'm able to write one measure:

int main(void){

    BYTE result;
    WORD s1;

        sprintf(buff, "Measure: %d\r\n", mes);
        result = pf_write(buff, sizeof(buff), &s1);

Now I'm trying to extend above code with pf_lseek to append another measure after previous one. Can someone give me a hint/suggestion how to achieve this?


1 Answer 1


I think you did not post the whole code, as pf_mount and pf_open are also needed to get started.

First of all - just don't close the file, call pf_write again with another sample.

Second - if you want to append to an existing file - open the file with pf_open and then try pf_lseek perhaps with a very high number (UINT32_MAX). I think that it will just set the pointer to the end of the file (check the error code).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.