diff options
author | Atle H. Havsø <atle@havso.net> | 2014-07-29 20:41:42 +0200 |
---|---|---|
committer | Atle H. Havsø <atle@havso.net> | 2014-07-29 20:41:42 +0200 |
commit | 5b0cb66688d5621171abc9ceb7c1747736d1d6a1 (patch) | |
tree | 9656cf86be10790335f9bc4512e876d73a9d62c3 | |
parent | ff300829ce9c4ece797f6d11b97b1100d7125d00 (diff) |
Working sensor data pull from hmc5983
-rw-r--r-- | drivers/hmc5983.h | 4 | ||||
-rw-r--r-- | main.cpp | 40 |
2 files changed, 10 insertions, 34 deletions
diff --git a/drivers/hmc5983.h b/drivers/hmc5983.h index 3d05e9c..9398f23 100644 --- a/drivers/hmc5983.h +++ b/drivers/hmc5983.h @@ -14,9 +14,9 @@ class HMC5983 { void read_register(uint8_t reg, uint8_t len, uint8_t *data) { cs.off(); if (len > 1) { - spi.transfer_byte(reg | (1 << 8) | (1 << 7)); + spi.transfer_byte(reg | (1 << 7) | (1 << 6)); } else { - spi.transfer_byte(reg | (1 << 8)); + spi.transfer_byte(reg | (1 << 7)); } while(len--) { *data++ = spi.transfer_byte(); @@ -78,8 +78,8 @@ int main() { RCC.enable(RCC.USB); usb.init(); - //RCC.enable(RCC.SPI2); - /* + RCC.enable(RCC.SPI2); + spi2_sck.set_mode(Pin::AF); spi2_sck.set_af(5); spi2_mosi.set_mode(Pin::AF); @@ -97,42 +97,18 @@ int main() { magn.init(); float buf[3] = {0,0,0}; - */ - s1.set_mode(Pin::AF); - s1.set_af(1); - s2.set_mode(Pin::AF); - s2.set_af(1); - - RCC.enable(RCC.TIM8); - TIM8.PSC = 168 - 1; - TIM8.ARR = 2500; - TIM8.CCER = (1 << 12) | (1 << 8) | (1 << 4) | (1 << 0); - TIM8.CCMR1 = (6 << 12) | (1 << 11) | (6 << 4) | (1 << 3); - TIM8.CCMR2 = (6 << 12) | (1 << 11) | (6 << 4) | (1 << 3); - TIM8.BDTR = (1 << 15); - TIM8.CCR1 = 1000; - TIM8.CCR2 = 1000; - TIM8.CCR3 = 1000; - TIM8.CCR4 = 1000; - TIM8.CR1 = (1 << 2) | (1 << 0); while(1) { usb.process(); - //uint8_t magn_status = magn.update(); - - //buf[0] = magn.x; - //buf[1] = magn.y; - //buf[2] = magn.z; - TIM8.CCR1 = 1000 + 100; - TIM8.CCR2 = 1000 + 100; - TIM8.CCR3 = 1000 + 100; - TIM8.CCR4 = 1000 + 100; - + uint8_t magn_status = magn.update(); + buf[0] = magn.x; + buf[1] = magn.y; + buf[2] = magn.z; + if(usb.ep_ready(1)) { - //usb.write(1, (uint32_t*)&magn.ident, sizeof(magn.ident)); - //usb.write(1, (uint32_t*)buf, sizeof(buf)); + usb.write(1, (uint32_t*)buf, sizeof(buf)); //usb.write(1, (uint32_t*)&magn_status, sizeof(magn_status)); } } |