I2C communications are working. <3
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -33,30 +33,6 @@ fn toggle_mcu_led(gpioa: &mut stm32f103::GPIOA) {
|
||||
});
|
||||
}
|
||||
|
||||
fn i2c1_write(addr: &u8, data: &[u8]) {
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
if let Some(ref mut i2c1) = *I2C1.borrow(cs).borrow_mut() {
|
||||
i2c1.cr1.modify(|_,w| w.start().set_bit());
|
||||
|
||||
while i2c1.sr1.read().sb().bit_is_clear() {}
|
||||
|
||||
i2c1.dr.write(|w| w.dr().bits(*addr));
|
||||
|
||||
while i2c1.sr1.read().addr().bit_is_clear() {}
|
||||
let _ = i2c1.sr2.read();
|
||||
|
||||
for byte in data {
|
||||
i2c1.dr.write(|w| w.dr().bits(*byte));
|
||||
while i2c1.sr1.read().tx_e().bit_is_clear() {}
|
||||
}
|
||||
|
||||
while i2c1.sr1.read().btf().bit_is_clear() {}
|
||||
|
||||
i2c1.cr1.modify(|_,w| w.stop().set_bit());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[interrupt]
|
||||
fn I2C1_EV() {
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
@@ -108,7 +84,8 @@ fn main() -> ! {
|
||||
// Configure peripheral
|
||||
i2c1.cr1.modify(|_,w| w.pe().enabled());
|
||||
i2c1.cr1.modify(|_,w| w.smbus().i2c());
|
||||
i2c1.oar1.modify(|_,w| w.add().bits(0x32));
|
||||
i2c1.cr1.modify(|_, w| w.ack().set_bit());
|
||||
i2c1.oar1.modify(|_,w| w.add().bits(0x32 << 1));
|
||||
i2c1.oar1.modify(|_,w| w.addmode().add7());
|
||||
|
||||
// Pass peripheral reference to global static
|
||||
|
||||
Reference in New Issue
Block a user