void gainSelectorLM94022(uint8_t gain) { /* Con esto podrí hacer una rutina q midiera VCC y A partir de esto * seleccionar la ganancia. */ switch (gain) { case VCC_SENSOR_1V5: GPIO_setOutputLowOnPin(GS_PORT,GS0); GPIO_setOutputLowOnPin(GS_PORT,GS1); break; case VCC_SENSOR_2V3: GPIO_setOutputHighOnPin(GS_PORT,GS0); GPIO_setOutputLowOnPin(GS_PORT,GS1); break; case VCC_SENSOR_3V0: GPIO_setOutputLowOnPin(GS_PORT,GS0); GPIO_setOutputHighOnPin(GS_PORT,GS1); break; case VCC_SENSOR_3V6: GPIO_setOutputHighOnPin(GS_PORT,GS0); GPIO_setOutputHighOnPin(GS_PORT,GS1); break; default: break; } }
void initButtons(void) { GPIO_setOutputHighOnPin(BUTTON1_PORT, BUTTON1_PIN); GPIO_setAsInputPinWithPullUpResistor(BUTTON1_PORT, BUTTON1_PIN); GPIO_clearInterrupt(BUTTON1_PORT, BUTTON1_PIN); GPIO_enableInterrupt(BUTTON1_PORT, BUTTON1_PIN); GPIO_setOutputHighOnPin(BUTTON2_PORT, BUTTON2_PIN); GPIO_setAsInputPinWithPullUpResistor(BUTTON2_PORT, BUTTON2_PIN); GPIO_clearInterrupt(BUTTON2_PORT, BUTTON2_PIN); GPIO_enableInterrupt(BUTTON2_PORT, BUTTON2_PIN); }
void led_on(unsigned char led_nr) { switch (led_nr) { case 1: OUTPUT1_TYPE == 0 ? GPIO_setOutputHighOnPin(OUTPUT1_BASEADDRESS, OUTPUT1_PORT, OUTPUT1_PIN): GPIO_setOutputLowOnPin(OUTPUT1_BASEADDRESS, OUTPUT1_PORT, OUTPUT1_PIN); break; case 2: OUTPUT2_TYPE == 0 ? GPIO_setOutputHighOnPin(OUTPUT2_BASEADDRESS, OUTPUT2_PORT, OUTPUT2_PIN): GPIO_setOutputLowOnPin(OUTPUT2_BASEADDRESS, OUTPUT2_PORT, OUTPUT2_PIN); break; case 3: OUTPUT3_TYPE == 0 ? GPIO_setOutputHighOnPin(OUTPUT3_BASEADDRESS, OUTPUT3_PORT, OUTPUT3_PIN): GPIO_setOutputLowOnPin(OUTPUT3_BASEADDRESS, OUTPUT3_PORT, OUTPUT3_PIN); break; } }
/* * ======== MSP_EXP430F5529LP_initWiFi ======== */ void MSP_EXP430F5529LP_initWiFi(void) { /* Configure EN & CS pins to disable CC3100 */ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2); GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN6); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN6); /* Configure SPI */ /* SPI CLK */ GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN2); /* MOSI/SIMO */ GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN0); /* MISO/SOMI */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN1); /* Configure IRQ pin */ GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P2, GPIO_PIN0); GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN0, GPIO_LOW_TO_HIGH_TRANSITION); /* Initialize SPI and WiFi drivers */ SPI_init(); WiFi_init(); }
void SYSNMI_ISR(void) #else #error Compiler not supported! #endif { switch (__even_in_range(SYSSNIV, SYSSNIV_CBDIFG)) { case SYSSNIV_NONE: break; case SYSSNIV_SVS: break; case SYSSNIV_UBDIFG: break; case SYSSNIV_ACCTEIFG: break; case SYSSNIV_MPUSEGPIFG: break; case SYSSNIV_MPUSEGIIFG: break; case SYSSNIV_MPUSEG1IFG: break; // segment 1 case SYSSNIV_MPUSEG2IFG: // segment 2 // Clear violation interrupt flag MPU_clearInterruptFlag(__MSP430_BASEADDRESS_MPU__, MPUSEG2IFG); // Turn LED on GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); while (1); case SYSSNIV_MPUSEG3IFG: break; // segment 3 case SYSSNIV_VMAIFG: break; case SYSSNIV_JMBINIFG: break; case SYSSNIV_JMBOUTIFG: break; case SYSSNIV_CBDIFG: break; default: break; } }
//***** Functions ************************************************************* void main (void) { // Stop watchdog timer // WDT_A_hold( WDT_A_BASE ); // Set pin P1.0 to output direction and initialize low // GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); // GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); initGPIO(); initClocks(); while(1) { // Turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Wait about a second __delay_cycles( ONE_SECOND ); // Turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Wait another second __delay_cycles( ONE_SECOND ); } }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Set pin P1.0 to output direction and initialize low GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Set switch 2 (S2) as input button (connected to P1.1) GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P2, GPIO_PIN1 ); while(1) { // Read pin P1.1 which is connected to push button 2 usiButton1 = GPIO_getInputPinValue ( GPIO_PORT_P2, GPIO_PIN1 ); if ( usiButton1 == GPIO_INPUT_PIN_LOW ) { // If button is down, turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } else { // If button is up, turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } } }
int16_t getLDRVoltageForLED(uint8_t selectedPort, uint16_t selectedPins) { //enable desired pins to turn on LED GPIO_setOutputHighOnPin(selectedPort, selectedPins); //delay so LDR can settle __delay_cycles(LED_DELAY); //read from LDR ADC_startConversion(__MSP430_BASEADDRESS_ADC__,ADC_SINGLECHANNEL); //wait for completion interrupt from ADC while(!isADCFinished()) { __delay_cycles(1000); } int16_t temp = lastConversionValue(); //disable LED GPIO_setOutputLowOnPin(selectedPort, selectedPins); return temp; }
void main (void) { //Stop watchdog timer WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //Set P1.x to output direction GPIO_setAsOutputPin(__MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 ); //Set all P1 pins HI GPIO_setOutputHighOnPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 ); //Enter LPM4 w/interrupt __bis_SR_register(LPM4_bits + GIE); //For debugger __no_operation(); }
void testInitIO() { /* * Configure LED pins as output. */ MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); }
//------------------------------------------------------------------------------ // GPIO ISR void gpio_isr(void) { uint32_t status; status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P6); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, status); msprf24_get_irq_reason(); // this updates rf_irq if (rf_irq & RF24_IRQ_TX) { status = 1; GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1); } if (rf_irq & RF24_IRQ_TXFAILED) { status = 0; GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0); } msprf24_irq_clear(RF24_IRQ_MASK); // Clear any/all of them }
//***************************************************************************** // // Writes a command to the CFAF128128B-0145T. This function implements the basic SPI // interface to the LCD display. // //***************************************************************************** void HAL_LCD_writeCommand(uint8_t command) { // Set to command mode GPIO_setOutputLowOnPin(LCD_DC_PORT, LCD_DC_PIN); /* USCI_B0 TX buffer ready? */ while (!EUSCI_B_SPI_getInterruptStatus(LCD_EUSCI_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)); SPI_transmitData(LCD_EUSCI_BASE,command); // Set back to data mode GPIO_setOutputHighOnPin(LCD_DC_PORT, LCD_DC_PIN); }
void vParTestSetLED( UBaseType_t uxLED, BaseType_t xValue ) { if( uxLED < partstNUM_LEDS ) { if( xValue == pdFALSE ) { GPIO_setOutputLowOnPin( ucPorts[ uxLED ], usPins[ uxLED ] ); } else { GPIO_setOutputHighOnPin( ucPorts[ uxLED ], usPins[ uxLED ] ); } } }
void blinkGreenLED() { uint16_t i; GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN7); for (i = ((uint16_t)-1); i > 0; i--) { // cheap delay _NOP(); } GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN7); for (i = ((uint16_t)-1); i > 0; i--) { // cheap delay _NOP(); } }
void msp430_i2c_disable(void) { if (!i2c.enabled) return; USCI_B_I2C_disable(USCI_B0_BASE); GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); GPIO_setOutputHighOnPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); i2c.enabled = 0; return; }
__interrupt void ADC12_ISR (void) { switch (__even_in_range(ADC12IV,34)){ case 0: break; //Vector 0: No interrupt case 2: break; //Vector 2: ADC overflow case 4: break; //Vector 4: ADC timing overflow case 6: //Vector 6: ADC12IFG0 //Is Memory Buffer 0 = A0 > 0.5AVcc? if (ADC12_getResults(__MSP430_BASEADDRESS_ADC12_PLUS__, ADC12_MEMORY_0) >= 0x7ff){ //set P1.0 GPIO_setOutputHighOnPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); } else { //Clear P1.0 LED off GPIO_setOutputLowOnPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); } //Exit active CPU __bic_SR_register_on_exit(LPM0_bits); case 8: break; //Vector 8: ADC12IFG1 case 10: break; //Vector 10: ADC12IFG2 case 12: break; //Vector 12: ADC12IFG3 case 14: break; //Vector 14: ADC12IFG4 case 16: break; //Vector 16: ADC12IFG5 case 18: break; //Vector 18: ADC12IFG6 case 20: break; //Vector 20: ADC12IFG7 case 22: break; //Vector 22: ADC12IFG8 case 24: break; //Vector 24: ADC12IFG9 case 26: break; //Vector 26: ADC12IFG10 case 28: break; //Vector 28: ADC12IFG11 case 30: break; //Vector 30: ADC12IFG12 case 32: break; //Vector 32: ADC12IFG13 case 34: break; //Vector 34: ADC12IFG14 default: break; } }
void testLedSet(LED_t led, bool on) { switch (led) { case Green: if (on) GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); else GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); break; case Red: break; case Yellow: break; } }
void HAL_LCD_SpiInit(void) { eUSCI_SPI_MasterConfig config = { EUSCI_B_SPI_CLOCKSOURCE_SMCLK, LCD_SYSTEM_CLOCK_SPEED, LCD_SPI_CLOCK_SPEED, EUSCI_B_SPI_MSB_FIRST, EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, EUSCI_B_SPI_3PIN }; SPI_initMaster(LCD_EUSCI_BASE, &config); SPI_enableModule(LCD_EUSCI_BASE); GPIO_setOutputLowOnPin(LCD_CS_PORT, LCD_CS_PIN); GPIO_setOutputHighOnPin(LCD_DC_PORT, LCD_DC_PIN); }
__interrupt void USCI_A1_ISR (void) { GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN3 ); /*make it HIGH because we are processing data*/ uint8_t received_byte = 0x00; static uint8_t rx_buffer[10] = {0x00}; static uint8_t index = 0; switch (__even_in_range(UCA1IV,4)) { //Vector 2 - RXIFG case 2: // received_byte = USCI_UART_receiveData(USCI_A1_BASE); // if(index<sizeof(rx_buffer)) // { // rx_buffer[index] = received_byte; // index++; //} //else // { //} received_byte = USCI_UART_receiveData(USCI_A1_BASE); /*good for debugging. reading the register clears the interupt flag?*/ bt_uart_manager(received_byte); /*pass the byte from the uart into this function which will store it and parse it accordingly*/ break; default: break; } GPIO_setOutputLowOnPin(GPIO_PORT_P4,GPIO_PIN3 ); /*make it low because we are ready to receive data*/ }
/* * Enable */ void loadRegisters() { GPIO_setAsOutputPin( RULE_PORT, RULE_ENABLE_PIN); GPIO_setOutputHighOnPin( RULE_PORT, RULE_ENABLE_PIN); }
void LED::set(const bool is_on) { is_on_ = is_on; isOn() ? GPIO_setOutputHighOnPin(pin_.port, pin_.pin) : GPIO_setOutputLowOnPin(pin_.port, pin_.pin); }
void Board_init(void) { // Setup XT1 and XT2 GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P5, GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 ); // Configure LED ports GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 ); GPIO_setOutputLowOnPin( GPIO_PORT_P8, GPIO_PIN1 + GPIO_PIN2 ); GPIO_setAsOutputPin( GPIO_PORT_P8, GPIO_PIN1 + GPIO_PIN2 ); // Configure button ports // Buttons on P1.7/P2.2 are inputs GPIO_setAsInputPin( GPIO_PORT_PA, GPIO_PIN7 + GPIO_PIN10 ); // Configure CapTouch ports GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 ); GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 ); GPIO_setOutputLowOnPin( GPIO_PORT_P6, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 ); GPIO_setAsInputPin( GPIO_PORT_P6, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 ); // Configure Cma3000 ports // ACCEL_INT pin is input GPIO_setAsInputPin( GPIO_PORT_P2, GPIO_PIN5 ); // SCK GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN7 ); // ACCEL_SIMO, ACCEL_CS, ACCEL_PWR to low GPIO_setOutputLowOnPin( GPIO_PORT_P3, GPIO_PIN3 + GPIO_PIN5 + GPIO_PIN6 ); // ACCEL_SOMI pin is input GPIO_setAsInputPin( GPIO_PORT_P3, GPIO_PIN4 ); // ACCEL_SIMO, ACCEL_CS, ACCEL_PWR as outp GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN3 + GPIO_PIN5 + GPIO_PIN6 ); // Configure Dogs102x6 ports // LCD_C/D, LCD_RST GPIO_setOutputLowOnPin( GPIO_PORT_P5, GPIO_PIN6 + GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P5, GPIO_PIN6 + GPIO_PIN7 ); // LCD_CS, LCD_BL_EN GPIO_setOutputLowOnPin( GPIO_PORT_P7, GPIO_PIN4 + GPIO_PIN6 ); GPIO_setAsOutputPin( GPIO_PORT_P7, GPIO_PIN4 + GPIO_PIN6 ); // SIMO, SCK GPIO_setOutputLowOnPin( GPIO_PORT_P4, GPIO_PIN1 + GPIO_PIN3 ); // SOMI pin is input GPIO_setAsInputPin( GPIO_PORT_P4, GPIO_PIN2 ); GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN1 + GPIO_PIN3 ); // Configure SDCard ports // SD_CS to high GPIO_setOutputHighOnPin( GPIO_PORT_P3, GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN7 ); // Configure Wheel ports // A5 ADC input GPIO_setAsInputPin( GPIO_PORT_P6, GPIO_PIN5 ); // POT_PWR GPIO_setOutputLowOnPin( GPIO_PORT_P8, GPIO_PIN0 ); GPIO_setAsOutputPin( GPIO_PORT_P8, GPIO_PIN0 ); // Configure unused ports for low power GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN6 ); GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN6 ); GPIO_setOutputLowOnPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 ); GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 ); GPIO_setOutputLowOnPin( GPIO_PORT_P4, GPIO_PIN0 + GPIO_PIN6 + GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN0 + GPIO_PIN6 + GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P5, GPIO_PIN1 ); GPIO_setAsOutputPin( GPIO_PORT_P5, GPIO_PIN1 ); GPIO_setOutputLowOnPin( GPIO_PORT_P6, GPIO_PIN6 + GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P6, GPIO_PIN6 + GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P7, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN5+ GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P7, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN5+ GPIO_PIN7 ); }
void main() { int err = 0, count = 0, bytesWritten = 0; char addr[5], i = '0'; char buf[32], data[64]; uint8_t status; uint32_t ACLKfreq; BYTE temp[100]; UINT bw = 0, btw; FRESULT iFResult; DWORD sizeBuf = 0; //Initialization Functions err = InitFunction(); err |= ADC_InitFunction(); err |= I2C_InitFunc(calData); err |= InitOneWire(); //Initialize the SD card Use_SD_CARD = YES; if(SD_CardInit()) { Use_SD_CARD = NO; } //Initialize the nRF wireless module ACLKfreq = MAP_CS_getACLK(); // get ACLK value to verify it was set correctly rf_crc = RF24_CRCO; rf_addr_width = (uint8_t)ADDRESS_WIDTH; rf_speed_power = RF24_SPEED_MIN | RF24_POWER_MAX; rf_channel = 120; msprf24_init(); // All RX pipes closed by default msprf24_open_pipe(0, 1); // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs msprf24_set_pipe_packetsize(0, (uint8_t)ADDRESS_WIDTH); // Dynamic payload length enabled (size=0) // Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31) msprf24_standby(); memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5); // addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '2'; w_tx_addr(addr); w_rx_addr(0, addr); // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node // needs to listen to the TX addr on pipe#0 to receive them. buf[0] = '1'; buf[1] = '\0'; // w_tx_payload(1, buf); w_tx_payload_noack(1, buf); msprf24_activate_tx(); if (rf_irq & RF24_IRQ_FLAGGED) { msprf24_get_irq_reason(); // this updates rf_irq if (rf_irq & RF24_IRQ_TX) status = 1; if (rf_irq & RF24_IRQ_TXFAILED) status = 0; msprf24_irq_clear(RF24_IRQ_MASK); // Clear any/all of them } memset(buf, 0, sizeof(buf)); MAP_Interrupt_enableMaster(); // MAP_Interrupt_setPriority(INT_TA0_0, 0x00); //Entering the main loop while(1) { while(Refresh == 0) { //Keep the process locked here until 'Refresh' is set high. } MAP_ADC14_toggleConversionTrigger(); Refresh = 0; //Get light value GetLightValue(&lux, &lightIndex); //Get temperature and pressure GetBaroTemp(calData, &temperature, &pressure); //Get temperature and humidity __delay_cycles(100); dht_start_read(); int t = dht_get_temp(); int h = dht_get_rh(); __delay_cycles(100); //For debug purposes printf("Temperature: %d\n", temperature); printf("Pressure: %d\n", pressure); printf("Lux: %d\n", lux); printf("Humidity: %d\n", h); //Form the string to send to base station sprintf(buf, "<T%003dP%000006dH%003dL%00005d>", temperature, pressure, h, lux); //transmit data GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); w_tx_payload((uint8_t)ADDRESS_WIDTH, buf); msprf24_activate_tx(); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); //open SD card if(Use_SD_CARD == YES) { iFResult = f_open(&g_sFileObject, "data.txt", FA_OPEN_EXISTING | FA_WRITE); count = 0; //if the first open fails, unmount and try again for 5 times while ((iFResult != FR_OK) && (count < 5)) { iFResult = f_mount(0, 0); count++; __delay_cycles(10000); iFResult = f_mount(0, &g_sFatFs); __delay_cycles(10000); iFResult |= f_open(&g_sFileObject, "data.txt", FA_WRITE | FA_CREATE_NEW); } // sizeBuf = strlen(temp) + 1; sizeBuf = sizeBuf + bw; sprintf(temp, "\n%d, %d, %d, %d ", temperature, pressure, lux, h); btw = strlen(temp); if(count < 5) { //Find the end of the file and write new data here iFResult = f_lseek(&g_sFileObject, sizeBuf); iFResult = f_write(&g_sFileObject, temp, btw, &bw); //close the file iFResult = f_close(&g_sFileObject); } } } }
//***************************************************************************** // // Set CS line // // This macro allows to set the Chip Select (CS) line // //***************************************************************************** void msp430_spi_b1_setCS(void) { GPIO_setOutputHighOnPin(LCD_SPI_CS_PORT, LCD_SPI_CS_PIN); }
//***** Main Function ********************************************************* void main (void) { uint16_t i = 0; uint16_t val = 0; uint16_t loc = 0; uint16_t status = 0; // Stop watchdog timer WDT_A_hold( WDT_A_BASE ); // Initialize GPIO initGPIO(); if ( erase != 0 ) // This lets you easily erase the flash by changing the value erase_infoB(); // of the "erase" variable before reaching this point in the code if ( fill != 0 ) // This lets you easily fill the flash by changing the value fill_infoB(); // of the "fill" variable before reaching this point in the code if (count[ 0 ] == 0xffff ) { val = 1; loc = 0; } else if ( count[ NUMBER_OF_WORDS-1 ] != 0xFFFF ) { val = count[ NUMBER_OF_WORDS-1 ]; erase_infoB(); loc = 0; } else { for ( i = 1; i < NUMBER_OF_WORDS-2; i++ ) { if ( count[ i ] == 0xffff ) { val = count[ i - 1 ]; val++; loc = i; break; } } } status = write_infoB_location( val, loc ); if ( status == 0 ) while( 1 ); // Inform the programmer how many times the board has been power-on reset // which isn't possible without some form of non-volaile memory printf( "This program has been power cycled %d times\n", val ); // Flash the LED 'count' number of times ... this way you can 'see' how many // times a power-on reset has occured, even if you can't read the printf() for ( i = 0; i < val; i++ ) { // Turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Wait about a second __delay_cycles( ONE_SECOND ); // Turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Wait another second __delay_cycles( HALF_SECOND ); } // Trap program here while(1); }
void bluetooth_init(){ GPIO_setAsOutputPin(BLUETOOTH_PW_PORT, BLUETOOTH_PW_PIN); GPIO_setOutputHighOnPin(BLUETOOTH_PW_PORT, BLUETOOTH_PW_PIN); }
/** Refresh the display */ void refreshLedDial() { //Refresh lower bank (LEDs 1-4) //LED 1 if (ledValue_==1) { GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1|GPIO_PIN2|GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); } //LED 2 if (ledValue_==2) { GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2|GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); } //LED 3 if (ledValue_==3) { GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1|GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); } //LED 4 if (ledValue_==4) { GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1|GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); } __delay_cycles(10000); //Delay 10ms //Refresh lower bank (LEDs 5-9) //LED 5 if (ledValue_==5) { GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1|GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); } //LED 6 if (ledValue_==6) { GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1|GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); } //LED 7 if (ledValue_==7) { GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2|GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); } //LED 8 if (ledValue_==8) { GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1|GPIO_PIN2|GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); } __delay_cycles(10000); //Delay 10ms }
void bluetooth_powerUp(){ GPIO_setOutputHighOnPin(BLUETOOTH_PW_PORT, BLUETOOTH_PW_PIN); }
/** * LED3 on: READY */ inline void led3_on(void) { GPIO_setOutputHighOnPin(LED3_PORT, LED3_PIN); }
int8_t msp430_i2c_write(unsigned char slave_addr, unsigned char reg_addr, unsigned char length, unsigned char const *data) { unsigned long start, cur; if (!i2c.enabled) return -1; if (!length) return 0; /* Populate struct. */ i2c.state = STATE_WRITING; i2c.slave_reg = reg_addr; i2c.data = (unsigned char*)data; i2c.length = length; //Specify slave address USCI_B_I2C_setSlaveAddress(USCI_B0_BASE, slave_addr ); //Set Master in transmit mode USCI_B_I2C_setMode(USCI_B0_BASE, USCI_B_I2C_TRANSMIT_MODE ); while(USCI_B_I2C_SENDING_STOP == USCI_B_I2C_masterIsStopSent(USCI_B0_BASE)); if(USCI_B_I2C_masterSendMultiByteStartWithTimeout(USCI_B0_BASE, i2c.slave_reg, I2C_TIMEOUT) == STATUS_FAIL) { USCI_B_I2C_masterSendMultiByteStop(USCI_B0_BASE); i2c.state = STATE_WAITING; msp430_i2c_disable(); msp430_delay_ms(1); GPIO_setOutputLowOnPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); msp430_delay_ms(1); GPIO_setOutputHighOnPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); msp430_i2c_init(); return -1; } msp430_get_clock_ms(&start); while (i2c.state != STATE_WAITING) { __bis_SR_register(LPM0_bits + GIE); msp430_get_clock_ms(&cur); if (cur >= (start + I2C_TIMEOUT_MS)) { USCI_B_I2C_masterSendMultiByteStop(USCI_B0_BASE); i2c.state = STATE_WAITING; msp430_i2c_disable(); msp430_delay_ms(1); GPIO_setOutputLowOnPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); msp430_delay_ms(1); GPIO_setOutputHighOnPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); msp430_i2c_init(); return -1; } } return 0; }