有没有办法在NodeMCU ESP8266的LUA中增加SD卡的写入速度?

我能达到的最大写入速度是2.4KB/秒,有没有办法增加这个速度?

我在NodeMCU ESP8266上使用LUA和User_Modules.h中的SPI模块。同时在user_config.h中启用 #define BUILD_FATFS。

我有一个数据记录器,每次采样920SPS或约1.1ms/样品,一次记录为10小时。1.1毫秒应该足够时间向SD卡写入两个字节或在采样之间的缓冲区中写入xxx个字节,但我所看到的最大写入速度是498毫秒写入1200字节或7毫秒写入3字节。这与SD Class 0标准的12.5MB/s相差甚远。记录器最终会错过约450个样本,当我将1200B写入SD卡时。


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)   --第二个参数是非标准SS/CS引脚的可选项
    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) --启用中断,上升沿有活性低电平==conv ready
    end)
end
点赞