void main (void) { initMCU(); while(1){ ad(); } }
/******************************************************************************* * @fn main * * @brief Runs the main routine * * @param none * * @return none */ void main(void) { // Initialize MCU and peripherals initMCU(); // Write radio registers registerConfig(); // Enter runRX, never coming back runRX(); }
/***************************************************************************//** * @brief Runs the main routine * * This function covers the main application code. * * @note Depending on the application, you can use either one or several * calls from the following functions from the SIGFOX Library: * * @note \li SfxSendFrame(message, length, NULL, NULL) : Send an Uplink frame * @note \li SfxSendFrame(message, length, ReceivedPayload, TRUE) : Downlink with ack * @note \li SfxSendBit( 0, NULL, NULL) : Send a bit * @note \li SfxSendOutOfBand() : Send OOB frame * @note \li SfxTxTestMode(nb_frames, channel_number) : Tx TestModeFrame activation ******************************************************************************/ void main(void) { SFX_error_t volatile err; // error returned from sigfox api functions. (For debug purpose) #if defined(AT_CMD) host_cmd_status_t hostCmdStatus; char cmd[40]; unsigned char length; #endif #if defined(PB_KEY) unsigned char buttonPressed; #endif //Initialize the memory dynamic_memory_init(); // Initialize MCU and Peripherals initMCU(); #ifdef __MSP430F5438A__ // Display welcome screen on LCD welcomeLCD(); #endif // Write the uplink and downlink frequencies if device is programmed for first time resetCF(); // SIGFOX library init err = SfxInit(); assert(SFX_ERR_NONE == err); // Infinite loop for(;;) { GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN7); // GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN7); // P4OUT |= 0x00; P4OUT &= ~BIT7; #if defined(AT_CMD) // Detect Carriage Return in the string if(uartGetRxEndOfStr() == END_OF_LINE_DETECTED) { // Reset end of string detection uartResetRxEndOfStr(); // Get the input string and its length length = uartGetRxStrLength(); uartGetStr(cmd, length); // Parse the string to find AT commands hostCmdStatus = parseHostCmd((unsigned char *)cmd, length); assert(HOST_CMD_NOT_FOUND != hostCmdStatus); } #endif #if defined(PB_KEY) buttonPressed = bspKeyPushed(BSP_KEY_ALL); // Detect button push to send the message if((buttonPressed == BSP_KEY_SELECT) || (buttonPressed == BSP_KEY_UP)) { #if defined(__MSP430F5438A__) // Update LCD updateLCD(); // Toggle LED indicators bspLedClear(BSP_LED_3); bspLedClear(BSP_LED_4); #endif bspLedClear(BSP_LED_2); bspLedSet(BSP_LED_1); if(buttonPressed == BSP_KEY_UP) { // Send uplink only frame err = SfxSendFrame(message, sizeof(message), NULL, NULL); } else if(buttonPressed == BSP_KEY_SELECT) { // Send a bi-directional frame err = SfxSendFrame(message, sizeof(message), ReceivedPayload, TRUE); } // Reset button status buttonPressed = 0; #if defined (__MSP430F5438A__) // Clear LED1 bspLedClear(BSP_LED_1); // LED indicator for sigfox API error status if (err == SFX_ERR_NONE) { bspLedSet(BSP_LED_3); } else { bspLedSet(BSP_LED_4); } // Update LCD updateLCD(); #elif defined (__MSP430F5529__) if (err == SFX_ERR_NONE) { bspLedSet(BSP_LED_2); } else { bspLedClear(BSP_LED_2); } #endif // Increment in message message[11]++; } else { #if defined (__MSP430F5438A__) // Set LED2 bspLedSet(BSP_LED_2); #elif defined (__MSP430F5529__) // Clear LED1 bspLedClear(BSP_LED_1); #endif //MSP } #endif //INTERFACE } }
/******************************************************************************* * @fn main * * @brief Runs the main routine * * @param none * * @return none */ void main(void) { uint8 writeByte; // Initialize MCU and peripherals initMCU(); // Write radio registers (preferred settings from SmartRF Studio) registerConfig(); // Application specific registers // FIFO_THR = 120 // GPIO0 = RXFIFO_THR // GPIO2 = PKT_SYNC_RXTX // GPIO3 = PKT_SYNC_RXTX writeByte = INFINITE_PACKET_LENGTH_MODE; cc112xSpiWriteReg(CC112X_PKT_CFG0, &writeByte, 1); writeByte = 0x78; cc112xSpiWriteReg(CC112X_FIFO_CFG, &writeByte, 1); writeByte = 0x00; cc112xSpiWriteReg(CC112X_IOCFG0, &writeByte, 1); writeByte = 0x06; cc112xSpiWriteReg(CC112X_IOCFG2, &writeByte, 1); writeByte = 0x06; cc112xSpiWriteReg(CC112X_IOCFG3, &writeByte, 1); bspLedSet(BSP_LED_ALL); // Calibrate the radio according to the errata note manualCalibration(); // Connect ISR function to GPIO0 ioPinIntRegister(IO_PIN_PORT_1, GPIO0, &rxFifoAboveThresholdISR); // Interrupt on falling edge ioPinIntTypeSet(IO_PIN_PORT_1, GPIO0, IO_PIN_RISING_EDGE); // Clear interrupt ioPinIntClear(IO_PIN_PORT_1, GPIO0); // Enable interrupt ioPinIntEnable(IO_PIN_PORT_1, GPIO0); // Connect ISR function to GPIO2 ioPinIntRegister(IO_PIN_PORT_1, GPIO2, &syncReceivedISR); // Interrupt on falling edge ioPinIntTypeSet(IO_PIN_PORT_1, GPIO2, IO_PIN_RISING_EDGE); // Clear interrupt ioPinIntClear(IO_PIN_PORT_1, GPIO2); // Enable interrupt ioPinIntEnable(IO_PIN_PORT_1, GPIO2); // Set up interrupt on GPIO3 (PKT_SYNC_RXTX) ioPinIntRegister(IO_PIN_PORT_1, GPIO3, &packetReceivedISR); // Interrupt on falling edge ioPinIntTypeSet(IO_PIN_PORT_1, GPIO3, IO_PIN_FALLING_EDGE); printWelcomeMessage(); while (TRUE) { switch (state) { //------------------------------------------------------------------ case RX_START: //------------------------------------------------------------------ trxSpiCmdStrobe(CC112X_SRX); pBufferIndex = rxBuffer; // Disable interrupt on GPIO3 ioPinIntDisable(IO_PIN_PORT_1, GPIO3); state = RX_WAIT; //------------------------------------------------------------------ case RX_WAIT: //------------------------------------------------------------------ if (packetReceived) { packetReceived = FALSE; // Check CRC and update LCD if CRC OK if ((rxBuffer[packetLength + 3]) & CRC_OK) updateLcd(); // Change to infinite packet length mode pktFormat = INFINITE; writeByte = INFINITE_PACKET_LENGTH_MODE; cc112xSpiWriteReg(CC112X_PKT_CFG0, &writeByte, 1); state = RX_START; } break; //------------------------------------------------------------------ default: //------------------------------------------------------------------ break; } } }
int main () { CHIP_Init(); //Initialize Chip initMCU(); initGPIO(); //Initialize GPIO sdi2c_Init(); //Initialize I2C initTimer(); //initialize timer for timer interuprt /* Setup SysTick Timer for 10 msec interrupts */ if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) { while (1) ; } /*Enable all sensors and GPS */ GPIO_PinOutSet(GPS_PORT, ENABLE); //Enable GPS Sensor board BMP180_GetCalData(); //Enable and get calibration data from BMP180 initLSM303_LowPower(); //Enable Accel in low power mode initL3GD20H_Normal(); //Enable Gyro in normal mode GPIO_PinOutToggle(EXT_LED, YEL_LED); /* Acceleromter Data */ Delay(10); LSM303_GetAccelData(); LSM303_PowerOff(); GPIO_PinOutToggle(EXT_LED, YEL_LED); /*Gyroscope Data */ Delay(10); L3GD20H_GetGyroData(); L3GD20H_PowerOff(); GPIO_PinOutToggle(EXT_LED, YEL_LED); /*Temperature/Barometric Pressure */ Delay(10); BMP180_GetTemp(); BMP180_GetPressure(); BMP180_CalcRealTemperature(); BMP180_CalcRealPressure(); GPIO_PinOutToggle(EXT_LED, YEL_LED); /*Power Sensor*/ INA219_GetVoltage(); GPIO_PinOutClear(EXT_LED, YEL_LED); GPIO_PinOutToggle(EXT_LED, GRE_LED); Delay(100); GPIO_PinOutToggle(EXT_LED, GRE_LED); /* GPS Information */ timeout = 0; //reset timeout initGPS(); //Initialize GPS UART coldrestart(); //Send cold restart command while(fullread == 0) { //while not a full read, do the following if(satfix == 1) { //if there is a satellite fix, then... GPIO_PinOutSet(EXT_LED, YEL_LED); //toggle LED for debug readdata(); //readdata timeout = 0; } if(timeout > 20) { GPIO_PinOutClear(EXT_LED, YEL_LED); GPStimeout(); break; } } GPIO_PinOutSet(EXT_LED, GRE_LED); Delay(500); printGPS(0); //Print GPS to screen for debug concact(); /* Infinite loop */ while(1) { if(GPIO_PinInGet(BUT_PORT, RIGHT_BUT) == 0) { r = r + 1; if(r > 2) { //wrap around to beginning r = 0; } printGPS(r); } if(GPIO_PinInGet(BUT_PORT, LEFT_BUT) == 0) { r = r - 1; if(r < 0) { //wrap around to beginning r = 2; } printSENSORS(); } // if(GPIO_PinInGet(GPS_PORT, FIX) == 1) { // GPIO_PinOutToggle(EXT_LED, RED_LED); // } } }