int main(void) { _delay_ms(1000); char buf[10], a = 0; init_UART_MM(); send_MM_cmd("Hi\r", 0); init_SPI(); Current_state.gps.x = 1; Current_state.gps.y = 2; Current_state.gps.z = 3; while(1) { _delay_ms(2000); a++; sprintf(buf, "sent %d", a); send_MM_cmd(buf, 0); slave_send (HM_DATA, (char *)&Current_state, sizeof (struct state)); } return 0; }
void poll_MM(void) { ///Temporary variables for magnetometer readings int16_t x, y, z; uint8_t tmp; ///Send the poll command send_MM_cmd("*00P\r"); x = ((int16_t)receive_MM()) << 8; x &= 0xFF00; x |= (int16_t)receive_MM(); y = ((int16_t)receive_MM()) << 8; y &= 0xFF00; y |= (int16_t)receive_MM(); z = ((int16_t)receive_MM()) << 8; z &= 0xFF00; z |= (int16_t)receive_MM(); receive_MM(); char buf[100]; sprintf(buf,"%d %d %d\r", x, y, z); send_preflight(buf, strlen(buf)); ///Convert the readings to Gauss Current_state.mm.B_x = ((float) x) / 15000; Current_state.mm.B_y = ((float) y) / 15000; Current_state.mm.B_z = ((float) z) / 15000; }