diff options
Diffstat (limited to 'examples/nrf/src/bin/twim.rs')
| -rw-r--r-- | examples/nrf/src/bin/twim.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/twim.rs b/examples/nrf/src/bin/twim.rs new file mode 100644 index 000000000..537cea160 --- /dev/null +++ b/examples/nrf/src/bin/twim.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | //! Example on how to read a 24C/24LC i2c eeprom. | ||
| 2 | //! | ||
| 3 | //! Connect SDA to P0.03, SCL to P0.04 | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | #![feature(min_type_alias_impl_trait)] | ||
| 8 | #![feature(impl_trait_in_bindings)] | ||
| 9 | #![feature(type_alias_impl_trait)] | ||
| 10 | #![allow(incomplete_features)] | ||
| 11 | |||
| 12 | #[path = "../example_common.rs"] | ||
| 13 | mod example_common; | ||
| 14 | |||
| 15 | use defmt::{panic, *}; | ||
| 16 | use embassy::executor::Spawner; | ||
| 17 | use embassy_nrf::twim::{self, Twim}; | ||
| 18 | use embassy_nrf::{interrupt, Peripherals}; | ||
| 19 | |||
| 20 | const ADDRESS: u8 = 0x50; | ||
| 21 | |||
| 22 | #[embassy::main] | ||
| 23 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 24 | info!("Initializing TWI..."); | ||
| 25 | let config = twim::Config::default(); | ||
| 26 | let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); | ||
| 27 | let mut twi = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config); | ||
| 28 | |||
| 29 | info!("Reading..."); | ||
| 30 | |||
| 31 | let mut buf = [0u8; 16]; | ||
| 32 | twi.write_then_read(ADDRESS, &mut [0x00], &mut buf).unwrap(); | ||
| 33 | |||
| 34 | info!("Read: {=[u8]:x}", buf); | ||
| 35 | } | ||
