Add readme to i2c fram module
This commit is contained in:
parent
65d48f4b02
commit
715771b991
30
libs/i2c-fram/README.md
Normal file
30
libs/i2c-fram/README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# I2C FRAM driver
|
||||||
|
|
||||||
|
This library provides a driver for this FRAM part: https://www.adafruit.com/products/1895
|
||||||
|
|
||||||
|
The memory is accessed one byte at a time. The library provides a utility functions
|
||||||
|
to write an entire buffer.
|
||||||
|
|
||||||
|
## Reading/writing byte
|
||||||
|
|
||||||
|
```
|
||||||
|
let addr = 100
|
||||||
|
i2c_fram.writeByte(addr, 42)
|
||||||
|
let val = i2c_fram.readByte(addr)
|
||||||
|
console.log(`${addr}: ${val}`)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Reading/writing a buffer
|
||||||
|
|
||||||
|
This code will log current time and acceleration in X axis every second.
|
||||||
|
|
||||||
|
```
|
||||||
|
let bufSz = 8
|
||||||
|
for (let addr = 0; addr < 0x8000; addr += bufSz) {
|
||||||
|
let buf = pins.createBuffer(bufSz)
|
||||||
|
buf.setNumber(NumberFormat.Int32LE, 0, input.runningTime())
|
||||||
|
buf.setNumber(NumberFormat.Int32LE, 4, input.acceleration(Dimension.X))
|
||||||
|
i2c_fram.writeBuffer(addr, buf)
|
||||||
|
basic.pause(1000)
|
||||||
|
}
|
||||||
|
```
|
@ -8,7 +8,9 @@ function toBuf(arr: number[]) {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_fram.writeBuffer(98, toBuf([1,2,3,4,5,6,7]))
|
i2c_fram.writeBuffer(98, toBuf([1, 2, 3, 4, 5, 6, 7]))
|
||||||
|
|
||||||
console.log("100:" + i2c_fram.readByte(100))
|
console.log("100:" + i2c_fram.readByte(100))
|
||||||
console.log("101:" + i2c_fram.readByte(101))
|
console.log("101:" + i2c_fram.readByte(101))
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"name": "i2c-fram",
|
"name": "i2c-fram",
|
||||||
"description": "AdaFruit I2C FRAM driver for micro:bit",
|
"description": "AdaFruit I2C FRAM driver for micro:bit",
|
||||||
"files": [
|
"files": [
|
||||||
|
"README.md",
|
||||||
"fram.ts"
|
"fram.ts"
|
||||||
],
|
],
|
||||||
"testFiles": [
|
"testFiles": [
|
||||||
|
Loading…
Reference in New Issue
Block a user