From 5a6e0b83fbbc3d3841be3384d32c0d4d6aec070c Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 4 Sep 2011 02:14:22 +0200 Subject: Transmit gyro values over zigbee. --- main.cpp | 21 ++++++++++++++++++--- usart.h | 2 +- xbee.h | 6 +++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index d9faac1..5a0cd4d 100644 --- a/main.cpp +++ b/main.cpp @@ -57,11 +57,24 @@ class PID { } }; +I2C i2c; +ITG3200 gyro(i2c); + void threadmain() { while(1) { GPIOB.ODR ^= 1 << 1; - xbee_send(3, (uint8_t*)"hei"); + uint8_t buf[] = { + gyro.x & 0xff, + gyro.x >> 8, + gyro.y & 0xff, + gyro.y >> 8, + gyro.z & 0xff, + gyro.z >> 8, + }; + + xbee_send(6, buf); + Time::sleep(100); } } @@ -84,10 +97,12 @@ int main() { GPIOB.CRH = 0x44444444; GPIOB.ODR = 1 << 1; - I2C i2c; + Time::sleep(10); + + //I2C i2c; i2c.enable(); - ITG3200 gyro(i2c); + //ITG3200 gyro(i2c); gyro.init(); PPMSum ppmsum; diff --git a/usart.h b/usart.h index ab7fb3f..8fde39a 100644 --- a/usart.h +++ b/usart.h @@ -9,7 +9,7 @@ void interrupt() { void usart_enable() { RCC.enable(RCC.USART1); - USART1.BRR = 7500; // 9600 baud + USART1.BRR = 625; // 115200 baud USART1.CR1 = 0x202c; Interrupt::enable(Interrupt::USART1); diff --git a/xbee.h b/xbee.h index 2b577b2..f99fe55 100644 --- a/xbee.h +++ b/xbee.h @@ -21,12 +21,12 @@ void xbee_send(int len, const uint8_t* buf) { usart_send(0x19); usart_send(0xf1); - usart_send(0x00); - usart_send(0x00); + usart_send(0xff); + usart_send(0xfe); usart_send(0x00); usart_send(0x00); - uint8_t chsum = 0x80; + uint8_t chsum = 0x83; // Payload for(int i = 0; i < len; i++) { -- cgit v1.2.3