Colibri Forth Cookbook

From Stm32World Wiki
Revision as of 14:03, 20 July 2023 by Niclas (talk | contribs) (→‎(Re)Initialize SPI)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Useful Forth routines for Colibri family of products, listed in no particular order. This will also act as in informal tutorial in how to program the Colibri System.

All examples assumes `hex` mode, unless otherwise stated or indicated.

(Re)Initialize I2C

i2c1-init

(Re)Initialize SPI

spi1-init

Select expansion slot

2 io-slot! ( set the expansion slot multiplexers to IO2

Load and Run program from expansion module's EEPROM

Save new program to expansion module's EEPROM

Get GPIO pin

portA pin5 gpio@

Set GPIO pin

portA pin5 high gpio! ( set gpio PA5 high )
portA pin5 low gpio! ( set gpio PA5 low )

Set multiple GPIO pins

portA pin5 pin6 or pin15 or high gpio! ( set gpio PA5, PA6 and PA15 high in a single write )

Write byte to I2C

41 1 61 >i2c1  ( writes 0x41, 0x42 and 0x43 to I2C address 0x61 )

Write 3 bytes to I2C

41 42 43 3 61 >i2c1  ( writes 0x41, 0x42 and 0x43 to I2C address 0x61 )

Read byte from I2C

1 61 i2c1> ( reads 1 byte from I2C address 0x61 on to the stack )

Read 5 bytes from I2C

5 61 i2c1> ( reads 5 bytes from I2C address 0x61 )

Write byte to SPI

Write 5 bytes to SPI

Read byte from SPI

Read 5 bytes from SPI

Toggle Gpio every 1 second