Skip to content
Snippets Groups Projects
Commit bedbda9d authored by Per Lindgren's avatar Per Lindgren
Browse files

test of i2c->spi wip6, read product + version emulated

parent ad8bf117
No related branches found
No related tags found
No related merge requests found
...@@ -64,70 +64,70 @@ const APP: () = { ...@@ -64,70 +64,70 @@ const APP: () = {
// 10 - 115 kHz // 10 - 115 kHz
// 11 - 58 kHz // 11 - 58 kHz
let i2c_addr = 0x50 >> 1; // let i2c_addr = 0x50 >> 1;
let i2c_command_conf = 0xF0; // let i2c_command_conf = 0xF0;
let i2c_conf_reg = (0b0 << 5) /* MSB First */ | // let i2c_conf_reg = (0b0 << 5) /* MSB First */ |
(0b11 << 2) /* Mode 3 */ | // (0b11 << 2) /* Mode 3 */ |
(0b00 << 0) /* 1843 kHz */; // (0b00 << 0) /* 1843 kHz */;
// (0b01 << 0) /* 461 kHz */; // // (0b01 << 0) /* 461 kHz */;
let x = i2c // let x = i2c
.write(i2c_addr, &[i2c_command_conf, i2c_conf_reg]) // .write(i2c_addr, &[i2c_command_conf, i2c_conf_reg])
.unwrap(); // .unwrap();
rprintln!("configure {:?}", x); // rprintln!("configure {:?}", x);
// cortex_m::asm::delay(10_000_000); // // cortex_m::asm::delay(10_000_000);
// write to spi with CS0 (command 01..0f) // // write to spi with CS0 (command 01..0f)
let i2c_command_cs0 = 0x01; // bit 0 set // let i2c_command_cs0 = 0x01; // bit 0 set
let pmw_command_product_id = 0x00; // let pmw_command_product_id = 0x00;
let pmw_command_product_version = 0x01; // let pmw_command_product_version = 0x01;
let x = i2c.write(i2c_addr, &[i2c_command_cs0, pmw_command_product_id, 0]); // let x = i2c.write(i2c_addr, &[i2c_command_cs0, pmw_command_product_id, 0]);
rprintln!("request product_id {:?}", x); // rprintln!("request product_id {:?}", x);
// cortex_m::asm::delay(10_000_000); // // cortex_m::asm::delay(10_000_000);
// read the result // // read the result
let mut buff = [0, 0, 0, 0]; // let mut buff = [0, 0, 0, 0];
rprintln!("buff {:?}", buff); // rprintln!("buff {:?}", buff);
let x = i2c.read(i2c_addr, &mut buff); // let x = i2c.read(i2c_addr, &mut buff);
// read the buffer // // read the buffer
cortex_m::asm::delay(100_000); // cortex_m::asm::delay(100_000);
rprintln!("data received {:?}", x); // rprintln!("data received {:?}", x);
rprintln!("data received {:?}", buff); // rprintln!("data received {:?}", buff);
let x = i2c.write(i2c_addr, &[i2c_command_cs0, pmw_command_product_version, 0]); // let x = i2c.write(i2c_addr, &[i2c_command_cs0, pmw_command_product_version, 0]);
rprintln!("request product_version {:?}", x); // rprintln!("request product_version {:?}", x);
// cortex_m::asm::delay(10_000_000); // // cortex_m::asm::delay(10_000_000);
// read the result // // read the result
let mut buff = [0, 0, 0, 0]; // let mut buff = [0, 0, 0, 0];
rprintln!("buff {:?}", buff); // rprintln!("buff {:?}", buff);
let x = i2c.read(i2c_addr, &mut buff); // let x = i2c.read(i2c_addr, &mut buff);
// read the buffer // // read the buffer
cortex_m::asm::delay(100_000); // cortex_m::asm::delay(100_000);
rprintln!("data received {:?}", x); // rprintln!("data received {:?}", x);
rprintln!("data received {:?}", buff); // rprintln!("data received {:?}", buff);
// // test of the abstractions // // test of the abstractions
// use embedded_hal::spi::MODE_3; use embedded_hal::spi::MODE_3;
// use SC18IS602::{Order, Speed, SH18IS602}; use SC18IS602::{Order, Speed, SH18IS602};
// let mut spi_emu = let mut spi_emu =
// SH18IS602::new(i2c, 0, Order::MsbFirst, MODE_3, Speed::Speed1843kHz, false); SH18IS602::new(i2c, 0, Order::MsbFirst, MODE_3, Speed::Speed1843kHz, false);
// rprintln!("spi_emu initialized"); rprintln!("spi_emu initialized");
// let mut id_request = [0x00]; let mut id_request = [0x00, 00];
// spi_emu.transfer(&mut id_request).unwrap(); spi_emu.transfer(&mut id_request).unwrap();
// rprintln!("id_request {:?}", id_request); rprintln!("id_request {:?}", id_request);
// let mut id_request = [0x00]; let mut v_request = [0x01, 00];
// spi_emu.transfer(&mut id_request).unwrap(); spi_emu.transfer(&mut v_request).unwrap();
// rprintln!("response {:?}", id_request); rprintln!("version_request {:?}", v_request);
} }
#[idle] #[idle]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment