{{pfw:banner.png}} ====== I2C device drivers ====== ===== The idea for I2C device drivers ===== There are lots of chips available using the I2C-protocol. These examples use the I2C implementation as [[en:pfw:i2c|described here]]. All of them need a specific device driver. To name some: sensors, memory, clocks, I/O, etc. Here you can add any driver you like to share. Preferably written in **Generic Forth**. But as we embrace the differences, you may also add them in a new folder for your own dialect ! ===== I2C drivers ===== * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/24C02.f|24C02]], EEPROM memory, this driver works for EEPROM & FRAM chips from 1 kBit to 2 kBit [[http://ww1.microchip.com/downloads/en/devicedoc/Atmel-3350-SEEPROM-AT24C64B-Datasheet.pdf|datasheet]] & examples: * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/24CL64.f|24CL64]], EEPROM memory, this driver works for EEPROM & FRAM chips from 32 kBit to 512 kBit [[https://4donline.ihs.com/images/VipMasterIC/IC/MCHP/MCHPS02656/MCHPS02656-1.pdf|datasheet]] & examples: EDMP ( ea -- ) - Dump EEPROM memory from address ea SHOW ( -- ) - Show string stored in EEPROM * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/APDS9300.f|APDS9300]], Light sensor [[https://docs.broadcom.com/docs/AV02-1077EN|datasheet]] & examples: APDS ( -- ) - Show light and infrared light data * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/PCA9632.f|PCA9632]], 4-bit LED driver [[https://www.nxp.com/docs/en/data-sheet/PCA9632.pdf|datasheet]] & examples: PCA-ON ( -- ) - Activate PCA9632 LED power switch >ON ( b -- ) - (De)activate LED power output modes * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/DS1307.f|DS1307]], Low power Real-Time Clock [[https://datasheets.maximintegrated.com/en/ds/DS1307.pdf|datasheet]] & examples: ALARM ( -- ) - Give every 10 seconds text string alarm signal TIMER ( s m -- ) - Give every s seconds and m minutes a text string CLOCK ( -- ) - Show an RTC each second on a new line, first set the RTC! * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/PCF8574.f|PCF8574]], 8-bit I/O extender [[https://www.nxp.com/docs/en/data-sheet/PCF8574_PCF8574A.pdf|datasheet]] & examples: RUNNER1 ( -- ) - Running light on the output chip RUNNER2 ( -- ) - Same running light with delay timing using the input chip SHOW ( -- ) - Copy input chip data to output chip * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/PCF8591.f|PCF8591]], 8-bit ADC/DAC (four inputs, one output) [[https://www.nxp.com/docs/en/data-sheet/PCF8591.pdf|datasheet]] & examples: ANALOG ( +n -- ) - Convert ADC input +n, output to a DAC and type on screen

8-Bit ADC/DAC

* [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/LM75.f|LM75]], Temperature sensor with 9-bit resolution and max. +-2 degree celcius accuracy [[https://datasheets.maximintegrated.com/en/ds/LM75.pdf|datasheet]] & examples: TEMPERATURE2 ( -- ) - Read & show 9-bit temperature continuously * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/TMP75.f|TMP75]], Temperature sensor with 12-bit resolution and max. +-1 degree celcius accuracy [[https://www.ti.com/lit/gpn/tmp75|datasheet]] & examples: TMP75-DEMO ( -- ) - Read & show temperature continuously * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/OLED|More on OLEDs]] ; OLED drivers, character sets, etc. * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/LCD|More on LCD's]] ; LCD drivers, character sets, etc. * [[https://github.com/project-forth-works/project-forth-works/blob/main/Communication-Protocols/I2C/Device-drivers/I2C-scanner.f|Scanner]] ; Scan your I2C network for connected devices ===== APDS9300 driver in pseudo code ===== Using the I2C driver as presented [[en:pfw:i2c]] Function: {AP-ADDR ( reg +n -- ) 29 perform device! perform {i2c-write or reg with 80 bus! Function: APDS@ ( reg -- byte ) 1 perform {ap-addr perform i2c} perform {i2c-read perform bus@ perform i2c} Function: APDS! ( byte reg -- ) 2 perform {ap-addr perform bus! perform i2c} Function: APDS-ON ( -- ) 3 0 perform apds! Function: APDS-ON ( -- ) 3 0 perform apds! Function: LIGHT ( -- u ) 0C do apds@ 100 times 0D do apds@ or Function: IR ( -- u ) 0E do apds@ 100 times 0F do apds@ or

The tiny APDS9300

===== APDS9300 in Generic Forth ===== hex : {AP-ADDR ( reg +n -- ) 29 device! {i2c-write 80 or bus! ; : APDS@ ( reg -- b ) 1 {ap-addr i2c} 1 {i2c-read bus@ i2c} ; : APDS! ( b reg -- ) 2 {ap-addr bus! i2c} ; : APDS-ON ( -- ) 3 0 apds! ; : APDS-OFF ( -- ) 0 0 apds! ; : LIGHT ( -- u ) 0C apds@ 0D apds@ b+b ; : IR ( -- u ) 0E apds@ 0F apds@ b+b ; ===== Implementations ===== Have a look in this directory for Generic Forth implementations. Or in the sub directories for implementations for different systems.