Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 810 Bytes

ads1263.md

File metadata and controls

35 lines (26 loc) · 810 Bytes

Read data from ADS1263

All 'adc:' and 'spi:' functions only put commands to internal buffer, :flush() sends all the data to MPSSE.

adc:data() is blocking till adc data (requested by adc:data_read()) is not transfered.

local spi = require ("spi")(0)
local ads1263 = require ("ads1263")

spi:init(9)  --30MHz / (9+1) = 3MHz sclk
spi:polarity(true)
spi:msb(true)
spi:flush()
spi:read()  -- some strage single byte sometimes left in buffer after init???

local adc = ads1263(spi, 0x08, 0x10)

print(("ADC ID: 0x%02X"):format(adc:read(adc.REG.ID))) -- read id 0x23

adc:reset()
adc:gain(0)
adc:mux(0xCC)   --VCC monitor
adc:rate(0x02)  --10Hz sampling rate
adc:pulse()
adc:flush()

adc:start()
adc:data_wait()
adc:data_read()
adc:flush()

local voltage = adc:data() * 5.0 / 2.0^32 * 4

print(voltage)