/** * Determines if the device is using bluetooth by * attempting to activate the bluetooth configuration * mode. Will fail if the baudrate stored in EEPROM * is incorrect, or if the device has been powered * on for longer than ~1 minute. All failures should * be false negatives. * * NOTE: Do not use after interrupts have been enabled. * * @return True if connected to bluetooth. */ bool coms_Bluetooth_Detect(void) { sei(); bool ret = false; usart_Init(SERIAL, data_Read_EEPROM(DATA_BT_BAUD_ADDR)); usart_Interrupt_RX(SERIAL, ENABLE); timer_Wait_MS(500); usart_Text(SERIAL, PSTR("$$$")); timer_Wait_MS(100); if ((comsData[0] == 'C') && (comsData[1] == 'M') && (comsData[2] == 'D')) { usart_Text(SERIAL, PSTR("---\r")); ret = true; } cli(); usart_Interrupt_RX(SERIAL, DISABLE); comsSize = 0; return ret; }
/** * Initializes the GPS communications by intializing * the apropriate uart connection and enabling interrupts. */ void gps_Init(void) { usart_Init(GPS, GPS_BAUD_INIT); timer_Wait_MS(1000); gps_Send_Msg(GPS_RATE_MSG); timer_Wait_MS(100); gpsThreshold = data_Read_EEPROM(DATA_GPS_THRESHOLD_ADDR); usart_Interrupt_RX(GPS, ENABLE); gps_Clear(); }
int main (void) { uint8_t ret, b, x; uint8_t ee[2]; // Set clock to full speed CLKPR = 0x80; CLKPR = 0x00; // Init timer Timer0Initialise (); usart_Init(12); usart_TxQueuePutStr("\n\r" "UART test\n\r" "-----------------\n\r"); interrupt_Enable(1); b = 5; while (1) { ret = usart_Receive(&x); if(ret){ usart_TxQueuePut('*'); b = x; ee[0] = b; ee[1] = ~b; eeprom_Write(66,ee,2); ee[0] = ee[1] = 0; } eeprom_Read(66,ee,2); usart_TxQueuePutDec(b); usart_TxQueuePutHex(b); usart_TxQueuePut('!'); usart_TxQueuePutHex(ee[0]); usart_TxQueuePutHex(ee[1]); usart_TxQueuePutStr("\n\r"); WaitMilliseconds(500); } }
/** * Initializes the usart responsible for serial communication. * Also turns on recieve interrupts over serial. */ void coms_Init(void) { int i; if (data_Read_EEPROM(DATA_BT_FLAG_ADDR) == DATA_FLAG_ON) { data_Write_EEPROM(DATA_BT_FLAG_ADDR, DATA_FLAG_OFF); coms_Bluetooth_Init(); } if (!(coms_Bluetooth_Detect())) { usart_Init(SERIAL, COMS_BAUD_115200); } for (i = 0; i < COMS_BUFFER_SIZE; i++) comsData[i] = COMS_EMPTY; usart_Interrupt_RX(SERIAL, ENABLE); }
/** * Initializes the bluetooth settings. Configures it * as a serial port. Also names the device PINPoint4+HEX.SN. * * NOTE: Do not use after interrupts have been enabled. */ void coms_Bluetooth_Init(void) { char rate[2]; switch (data_Read_EEPROM(DATA_BT_BAUD_ADDR)) { case COMS_BAUD_115200: rate[0] = '1'; rate[1] = '1'; break; case COMS_BAUD_57600: rate[0] = '5'; rate[1] = '7'; break; case COMS_BAUD_38400: rate[0] = '3'; rate[1] = '8'; break; case COMS_BAUD_19200: rate[0] = '1'; rate[1] = '9'; break; case COMS_BAUD_9600: rate[0] = '9'; rate[1] = '6'; break; default: rate[0] = '1'; rate[1] = '1'; data_Write_EEPROM(DATA_BT_BAUD_ADDR, DATA_DEFAULT_BT_BAUD); break; } uint32_t sn = 0; sn += (uint32_t)data_Read_EEPROM(DATA_SN_24_ADDR) << 24; sn += (uint32_t)data_Read_EEPROM(DATA_SN_16_ADDR) << 16; sn += (uint32_t)data_Read_EEPROM(DATA_SN_8_ADDR) << 8; sn += (uint32_t)data_Read_EEPROM(DATA_SN_0_ADDR); timer_Wait_MS(1000); int i; for (i = 0; i < COMS_NUM_BAUD; i++) { usart_Init(SERIAL, comsBauds[i]); timer_Wait_MS(1000); usart_Text(SERIAL, PSTR("$$$")); timer_Wait_MS(100); usart_Text(SERIAL, PSTR("SU,")); usart_Write(SERIAL, rate[0]); usart_Write(SERIAL, rate[1]); usart_Write(SERIAL, '\r'); timer_Wait_MS(100); usart_Text(SERIAL, PSTR("SC,1101\r")); timer_Wait_MS(100); usart_Text(SERIAL, PSTR("SS,SerialPort\r")); timer_Wait_MS(100); usart_Text(SERIAL, PSTR("SI,0200\r")); timer_Wait_MS(100); usart_Text(SERIAL, PSTR("SJ,0100\r")); timer_Wait_MS(100); usart_Text(SERIAL, PSTR("SN,PINPoint4")); usart_Print_Num(SERIAL, sn); usart_Write(SERIAL, '\r'); timer_Wait_MS(100); usart_Text(SERIAL, PSTR("---\r")); timer_Wait_MS(100); } }