【AT-START-F425测评】利用U盘文件存储功能实现数据记录
<p style="text-align:justify">前面介绍了以U盘文件的读取功能来实现数码相框功能,这次说一下利用文件存储功能来充当数据记录装置。</p><p>当然要进行记录就必须有数据,其获取的方式可以是通过计时器来产生,也可以由传感器来获得,或是通过ADC来采集。</p>
<p>为便于测试,这里是将数据写到数组中,然后进行一次性写入。</p>
<p>所涉及的函数为usbh_user_application(),其内容为:</p>
<pre>
<code class="language-cpp">extern int8_t read_datp;
static usb_sts_type usbh_user_application(void)
{
usb_sts_type status = USB_OK;
FRESULT res;
uint32_t len;
uint8_t write_data =
{0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x41,0x42,0x61,0x62};
res = f_mount(&fs, "", 0);
if(res == FR_OK)
{
if(f_open(&file, "0:AT32.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
USBH_DEBUG("Open AT32.txt failed");
}
else
{
res = f_write(&file, write_data, sizeof(write_data), &len);
if(res != FR_OK || len == 0)
{
USBH_DEBUG("Write AT32.txt failed");
}
else
{
USBH_DEBUG("Write AT32.txt Success");
}
f_close(&file);
}
}
return status;
}</code></pre>
<p> </p>
<p>经下载测试,在U盘中已生成一个文本文件AT32.txt,其内容如图1所示。</p>
<p> </p>
<p>图1 U盘文件内容</p>
<p> </p>
<p>在数据检测记录装置的设计中,其硬件构成如图2所示。</p>
<p> </p>
<p>图2 硬件构成</p>
<p> </p>
<p>在使用温度大气压传感器BMP085进行检测的情况下,其数据检测记录如图3所示。</p>
<p> </p>
<p>图3 记录效果</p>
<p> </p>
<p>实现该功能的功能函数为:</p>
<pre>
<code class="language-cpp">static usb_sts_type usbh_user_application(void)
{
usb_sts_type status = USB_OK;
FRESULT res;
uint32_t len;
uint8_t write_data = {'t','=',0x32,0x30,'C',' ','p','=',0x31,0x30,0x32,0x34,'K','P','a',0xd,0xa};
uint8_t read_data = {0};
uint8_t data = {0};
uint8_t datb = {' '};
uint16_t i;
res = f_mount(&fs, "", 0);
if(res == FR_OK)
{
if(f_open(&file, "0:AT32.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
USBH_DEBUG("Open AT32.txt failed");
}
else
{
i=0;
data=' ';
res = f_write(&file, datb, sizeof(datb), &len);
// 键控采集
while(gpio_input_data_bit_read(GPIOA, GPIO_PINS_0)==0)
{
bmp085Convert();
data = i/1000+'0';
data = (i%1000)/100+'0';
data = (i%100)/10+'0';
data = i%10+'0';
res = f_write(&file, data, sizeof(data), &len);
res = f_write(&file, write_data, sizeof(write_data), &len);
usb_delay_ms(1000);
i++;
}
f_close(&file);
}
f_mount(NULL, "", 0);
}
return status;
}</code></pre>
<p> </p>
<p>此外,利用U盘写入功能还可以构建软字库,其测试效果见图4所示。在显示界面中,“鸿雁”2字是通过读取字库来实现的,而单个“鸿”字则是通过读取U盘来实现的。</p>
<p> </p>
<p>图4 汉字显示</p>
<p> </p>
<p>由此可知,AT-START-F425开发板的文件读写功能实在是强大!</p>
<p>看楼主对AT-START-F425开发板的文件读写测试,感觉是比较厉害</p>
Jacktang 发表于 2022-5-3 09:54
看楼主对AT-START-F425开发板的文件读写测试,感觉是比较厉害
<p>这是AT-START-F425的特色嘛,应该重视和体验。</p>
<p>这片子的USB开发麻烦吗、</p>
freebsder 发表于 2022-5-7 16:14
这片子的USB开发麻烦吗、
<p>个人觉得比较好用,与CH32V103差不多。</p>
页:
[1]