embassy/examples/nrf52840/src/bin/twim.rs

35 lines
899 B
Rust
Raw Normal View History

2021-05-26 18:15:37 +02:00
//! Example on how to read a 24C/24LC i2c eeprom.
//!
//! Connect SDA to P0.03, SCL to P0.04
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::Spawner;
2021-05-26 18:15:37 +02:00
use embassy_nrf::twim::{self, Twim};
use embassy_nrf::{bind_interrupts, peripherals};
2022-06-12 22:15:44 +02:00
use {defmt_rtt as _, panic_probe as _};
2021-05-26 18:15:37 +02:00
const ADDRESS: u8 = 0x50;
bind_interrupts!(struct Irqs {
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0 => twim::InterruptHandler<peripherals::TWISPI0>;
});
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_nrf::init(Default::default());
2021-05-26 18:15:37 +02:00
info!("Initializing TWI...");
let config = twim::Config::default();
let mut twi = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config);
2021-05-26 18:15:37 +02:00
info!("Reading...");
let mut buf = [0u8; 16];
unwrap!(twi.blocking_write_read(ADDRESS, &mut [0x00], &mut buf));
2021-05-26 18:15:37 +02:00
info!("Read: {=[u8]:x}", buf);
}