Add readme to i2c fram module

This commit is contained in:
Michal Moskal 2016-04-05 18:21:15 -07:00
parent 65d48f4b02
commit 715771b991
3 changed files with 34 additions and 1 deletions

30
libs/i2c-fram/README.md Normal file
View 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)
}
```

View File

@ -8,7 +8,9 @@ function toBuf(arr: number[]) {
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("101:" + i2c_fram.readByte(101))

View File

@ -2,6 +2,7 @@
"name": "i2c-fram",
"description": "AdaFruit I2C FRAM driver for micro:bit",
"files": [
"README.md",
"fram.ts"
],
"testFiles": [