【发布时间】:2021-07-28 04:00:46
【问题描述】:
我能达到的最大写入速度是 2.4 KB/s。有没有办法增加这个?
在 NodeMCU ESP8266 上使用 LUA 和 User_Modules.h 中的 SPI 模块。 #define BUILD_FATFS 也在 user_config.h 中启用。
我有一个数据记录器,它一次采样 920SPS 或 ~1.1ms/Sample 10 小时。 1.1 ms 应该是很多时间将两个字节写入 SD 卡或样本之间的 xxx 字节缓冲区,但是我看到的最大写入速度是 498 ms 写入 1200 字节或 7ms 写入 3 字节。这与 12.5MB/s 的 SD 0 类标准相去甚远。当我将 1200 B 转储到卡上时,记录器最终会丢失约 450 个样本。
local adc1 = nil
local t_tbl={}
local n=1
function adcReady(_,_,c)
_,_, adctbl[n], _ = adc1:read()
n=n+1
if n>400 then
t_tbl[1]=tmr.now()
file.open("/SD0/sddata.txt","a")
for k,v in ipairs(adctbl) do
file.write(v..",")
adctbl[k]=nil
end
file.close()
t_tbl[2]=tmr.now()
print(t_tbl[2] - t_tbl[1])
n=1
end
end
do
local adc = {
ADC1_ID = 0,
ADC1_ADDRESS = ads1115.ADDR_GND,
GAIN = ads1115.GAIN_4_096V,
SAMPLES = ads1115.DR_920SPS,
CHANNEL = ads1115.SINGLE_0,
MODE = ads1115.CONTINUOUS,
CONV_READY = ads1115.CONV_RDY_1,
}
i2c.setup(i2c0.id, i2c0.sda, i2c0.scl, i2c0.speed)
ads1115.reset()
adc1 = ads1115.ads1015(adc.ADC1_ID, adc.ADC1_ADDRESS)
adc1:setting(adc.GAIN, adc.SAMPLES, adc.CHANNEL, adc.MODE, adc.CONV_READY)
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 2, spi.HALFDUPLEX)
vol = file.mount("/SD0", 8) -- 2nd parameter is optional for non-standard SS/CS pin
file.open("/SD0/sddata.txt","w+")
file.close()
tmr.create():alarm(1000,tmr.ALARM_SINGLE,function()
gpio.mode(i2c0.conv_rdy,gpio.INT)
gpio.trig(i2c0.conv_rdy,'up', adcReady) --enable interrupt, active low rising edge==conv ready
end)
end
【问题讨论】:
-
选择最便宜的解决方案并尝试从中获得高端品质是很有趣的。将您的工具更改为为初学者编写的 C 语言。您使用的是儿童版,没有任何严肃的项目可以考虑在 ESP8266 上使用 Lua 来完成 RT 更接近的任务。
-
哦,我不知道 LUA 是为孩子们准备的。我刚开始使用 esp8266,我不喜欢 arduino 的 c 和 c++ 混搭。认为 LUA 会给我一个新的挑战,让我在业余时间学习一门新语言。
-
Lua 是一种有趣的语言,问题是你在平台上运行它,其他任务超载。
-
@0andriy 我怀疑这会说服你,但 Lua 肯定不(只是)为孩子们准备的。 en.wikipedia.org/wiki/List_of_applications_using_Lua。如果 NodeMCU Lua 足以运行商业 ESP8266/ESP32 家庭安全系统(而不是家庭自动化),它可能足以满足许多其他用例。话虽如此,看到 NodeMCU Lua 和使用例如本地 C/C++ 解决方案之间的这个特定任务的速度/吞吐量比较会很有趣。 Arduino 核心。
-
和@MarcelStör,你似乎完全错过了我的观点,我建议重新阅读我上面的cmets。
标签: lua esp8266 sd-card spi nodemcu