Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
81 lines (69 sloc) 1.95 KB
//! Endlessly fill the screen with characters from the alphabet
//!
//! This example is for the STM32F103 "Blue Pill" board using I2C1.
//!
//! Wiring connections are as follows for a CRIUS-branded display:
//!
//! ```
//! Display -> Blue Pill
//! (black) GND -> GND
//! (red) +5V -> VCC
//! (yellow) SDA -> PB9
//! (green) SCL -> PB8
//! ```
//!
//! Run on a Blue Pill with `cargo run --example terminal_i2c`.
#![no_std]
#![no_main]
use core::fmt::Write;
use cortex_m_rt::{entry, exception, ExceptionFrame};
use panic_halt as _;
use ssd1306::{prelude::*, Builder, I2CDIBuilder};
use stm32f1xx_hal::{
i2c::{BlockingI2c, DutyCycle, Mode},
prelude::*,
stm32,
};
#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();
let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
let scl = gpiob.pb8.into_alternate_open_drain(&mut gpiob.crh);
let sda = gpiob.pb9.into_alternate_open_drain(&mut gpiob.crh);
let i2c = BlockingI2c::i2c1(
dp.I2C1,
(scl, sda),
&mut afio.mapr,
Mode::Fast {
frequency: 400_000.hz(),
duty_cycle: DutyCycle::Ratio2to1,
},
clocks,
&mut rcc.apb1,
1000,
10,
1000,
1000,
);
let interface = I2CDIBuilder::new().init(i2c);
let mut disp: TerminalMode<_> = Builder::new().connect(interface).into();
disp.init().unwrap();
let _ = disp.clear();
/* Endless loop */
loop {
for c in 97..123 {
let _ = disp.write_str(unsafe { core::str::from_utf8_unchecked(&[c]) });
}
for c in 65..91 {
let _ = disp.write_str(unsafe { core::str::from_utf8_unchecked(&[c]) });
}
}
}
#[exception]
fn HardFault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
You can’t perform that action at this time.