cancel
Showing results for 
Search instead for 
Did you mean: 

How can I write every second with USB MSC STM32f105

umitguleer
Associate II
Posted on December 13, 2015 at 18:14

Hi everyone,

I wanna write my variable to USB every second but I can't.

I think it can be in while loop 

f_mount(0, &fatfs);

    

    if(f_open(&file, ''0:OLCUM.CSV'',FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)

    { 

   

                     sprintf (king, '' %d\n '', saniye1);

                      bytesToWrite = sizeof(king);

                      f_lseek(&file, file.fsize); // Seek to tail

                      res= f_write (&file, king, bytesToWrite, (void *)&bytesWritten);

                      f_sync(&file);

      f_close(&file);

      f_mount(0, NULL); 

or in while loop;

 USBH_Process(&USB_OTG_Core, &USB_Host);

 but I couldnt..

What can I do??

but

I could not.

but

I could not.

but

I could not.

4 REPLIES 4
Posted on December 13, 2015 at 19:54

Ok, so have your SysTick interrupt increment a 1ms tick counter, and then wait for it to advance 1000 ticks?

unsigned int Last = SystemTick;

while(1)

{

  unsigned int Current = SystemTick;

// ..

  if ((Current - Last) >= 1000)

  {

     Last = Current;

    Do1HzStuff();

  }

// ..

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
umitguleer
Associate II
Posted on December 14, 2015 at 10:17

yes clive,

I have systick and I can control relay every second and at the same time, I wanna write usb every second for my variable such as adc value.

which commands should I use?

I have usb library such as atollic examples 10C

Can I write in a while loop?

By the way, I've already written once. I wanna every second for adc value

but

I could not.

but

I could not.

but

I could not.

Posted on December 14, 2015 at 15:29

I don't use Atollic...

Wait for 1s to pass in the idle/core loop

volatile unsigned int systemTick = 0; // Incremented in 1ms SysTick
// ..
f_mount(0, &fatfs);
f_open(&file, ''0:OLCUM.CSV'',FA_CREATE_ALWAYS | FA_WRITE)
// ..
unsigned int Last = SystemTick;
// ..
while(1)
{
unsigned int Current = SystemTick;
// ..
if ((Current - Last) >= 1000)
{
Last = Current; // Or Last += 1000;
res= f_write (&file, sizeof(king), bytesToWrite, (void *)&bytesWritten);
f_sync(&file); // doing this each time is inefficient
}
// ..
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..