void initI2CModule(void) { unsigned int flags = EUSCI_B_I2C_TRANSMIT_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_TRANSMIT_INTERRUPT1 | EUSCI_B_I2C_RECEIVE_INTERRUPT1 | EUSCI_B_I2C_STOP_INTERRUPT | EUSCI_B_I2C_NAK_INTERRUPT; #if 0 /* Select Port B1 for I2C - Set Pin 4, 5 to input Primary Module Function, * (UCB1SIMO/UCB1SDA, UCB1SOMI/UCB1SCL). */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN4 + GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION); /* eUSCI I2C Slave Configuration */ I2C_initSlave(EUSCI_B1_BASE, SLAVE_ADDRESS, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); I2C_initSlave(EUSCI_B1_BASE, 0xC, EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_RECEIVE_MODE); /* Enable the module and enable interrupts */ I2C_enableModule(EUSCI_B1_BASE); MAP_I2C_clearInterruptFlag(EUSCI_B1_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0); MAP_I2C_enableInterrupt(EUSCI_B1_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0); MAP_Interrupt_enableInterrupt(INT_EUSCIB1); #else /* eUSCI I2C Slave Configuration */ I2C_initSlave(EUSCI_B0_BASE, SLAVE_ADDRESS, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); #if 1 I2C_initSlave(EUSCI_B0_BASE, 0xC, EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); #endif /* Select Port B2 for I2C - Set Pin 6, 7 to input Primary Module Function */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* Define the SMbus alert pin */ MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN0); MAP_GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN0); I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE); /* Enable the module and enable interrupts */ I2C_enableModule(EUSCI_B0_BASE); MAP_I2C_clearInterruptFlag(EUSCI_B0_BASE, flags); MAP_Interrupt_setPriority(INT_EUSCIB0, configMAX_SYSCALL_INTERRUPT_PRIORITY); MAP_I2C_enableInterrupt(EUSCI_B0_BASE, flags); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); #endif }
/** * Called to set the eUSCI module in 'master' mode */ void DWire::_initMaster(const eUSCI_I2C_MasterConfig * i2cConfig) { // Initialise the pins MAP_GPIO_setAsPeripheralModuleFunctionInputPin(modulePort, modulePins, GPIO_PRIMARY_MODULE_FUNCTION); // Initializing I2C Master to SMCLK at 400kbs with no autostop MAP_I2C_initMaster(module, i2cConfig); // Specify slave address MAP_I2C_setSlaveAddress(module, slaveAddress); // Set Master in transmit mode MAP_I2C_setMode(module, EUSCI_B_I2C_TRANSMIT_MODE); // Enable I2C Module to start operations MAP_I2C_enableModule(module); // Enable and clear the interrupt flag MAP_I2C_clearInterruptFlag(module, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT + EUSCI_B_I2C_RECEIVE_INTERRUPT0); // Enable master interrupts MAP_I2C_enableInterrupt(module, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT + EUSCI_B_I2C_RECEIVE_INTERRUPT0); // Register the interrupts on the correct module MAP_Interrupt_enableInterrupt(intModule); MAP_Interrupt_enableMaster(); }
void DWire::_initSlave( void ) { // Init the pins MAP_GPIO_setAsPeripheralModuleFunctionInputPin( modulePort, modulePins, GPIO_PRIMARY_MODULE_FUNCTION ); // initialise driverlib MAP_I2C_initSlave( module, slaveAddress, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE ); // Enable the module and enable interrupts MAP_I2C_enableModule( module ); MAP_I2C_clearInterruptFlag( module, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_STOP_INTERRUPT | EUSCI_B_I2C_TRANSMIT_INTERRUPT0 | EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT ); MAP_I2C_enableInterrupt( module, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_STOP_INTERRUPT | EUSCI_B_I2C_TRANSMIT_INTERRUPT0 | EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT ); /* Enable the clock low timeout */ EUSCI_B_CMSIS( module )->CTLW1 = (EUSCI_B_CMSIS( module )->CTLW1 & ~EUSCI_B_CTLW1_CLTO_MASK) | 0xC0; MAP_Interrupt_enableInterrupt( intModule ); MAP_Interrupt_enableMaster( ); }
static void prvSetupHardware( void ) { extern void FPU_enableModule( void ); /* The clocks are not configured here, but inside main_full() and main_blinky() as the full demo uses a fast clock and the blinky demo uses a slow clock. */ /* Stop the watchdog timer. */ MAP_WDT_A_holdTimer(); /* Ensure the FPU is enabled. */ FPU_enableModule(); /* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION ); MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); MAP_GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); /* Enable S2 and LED2 */ MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 ); MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN1 ); MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1); MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN2 ); MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2); MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4); MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN4); MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4); MAP_Interrupt_enableInterrupt(INT_PORT1); }
//select menu state machine void menu_select() { if(menu_state == 1) { P1OUT &= ~BIT0; send_on_bool = 1; MAP_Interrupt_disableInterrupt(INT_ADC14); active_bool = 0; view_activity_menu(); state2 = 0; menu_state = 6; } else if (menu_state == 2) { P1OUT |= BIT0; send_on_bool = 1; steps_taken = 0; active_bool = 1; MAP_Interrupt_enableInterrupt(INT_ADC14); menu_state = 0; backlight_off(); } else if (menu_state == 3) { goal_steps = 10; set_goal_menu1(); menu_state = 5; } else if (state2) { view_activity_menu(); state2 = 0; menu_state = 6; } else if (menu_state == 5) { send_goal_bool = 1; menu_state = 0; backlight_off(); } else if (menu_state == 6) { menu_state = 0; backlight_off(); } }
int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); /* Selecting P1.2 and P1.3 in UART mode */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /* Setting DCO to 12MHz */ CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12); /* Configuring UART Module */ MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* Enable UART module */ MAP_UART_enableModule(EUSCI_A0_MODULE); /* Enabling interrupts */ MAP_UART_enableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT); MAP_Interrupt_enableInterrupt(INT_EUSCIA0); MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableMaster(); while(1) { MAP_PCM_gotoLPM0(); } }
int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); /* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Setting DCO to 48MHz (upping Vcore) */ MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); /* Configuring UART Module */ MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* Enable UART module */ MAP_UART_enableModule(EUSCI_A0_MODULE); /* Enabling interrupts */ MAP_UART_enableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT); MAP_Interrupt_enableInterrupt(INT_EUSCIA0); MAP_Interrupt_enableSleepOnIsrExit(); while(1) { MAP_UART_transmitData(EUSCI_A0_MODULE, TXData); MAP_Interrupt_enableSleepOnIsrExit(); MAP_PCM_gotoLPM0InterruptSafe(); } }
void vInitialiseTimerForIntQueueTest( void ) { /* Configure the timer channels. */ MAP_Timer32_initModule( (uint32_t)TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE ); MAP_Timer32_setCount( (uint32_t)TIMER32_0_BASE, CS_getMCLK() / tmrTIMER_0_FREQUENCY ); MAP_Timer32_enableInterrupt( (uint32_t)TIMER32_0_BASE ); MAP_Timer32_startTimer( (uint32_t)TIMER32_0_BASE, false ); MAP_Interrupt_setPriority( INT_T32_INT1, tmrLOWER_PRIORITY ); MAP_Interrupt_enableInterrupt( INT_T32_INT1 ); MAP_Timer32_initModule( (uint32_t)TIMER32_1_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE ); MAP_Timer32_setCount( (uint32_t)TIMER32_1_BASE, CS_getMCLK() / tmrTIMER_1_FREQUENCY ); MAP_Timer32_enableInterrupt( (uint32_t)TIMER32_1_BASE ); MAP_Timer32_startTimer( (uint32_t)TIMER32_1_BASE, false ); MAP_Interrupt_setPriority( INT_T32_INT2, tmrHIGHER_PRIORITY ); MAP_Interrupt_enableInterrupt( INT_T32_INT2 ); }
int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); MAP_Interrupt_enableSleepOnIsrExit(); resPos = 0; /* Setting up clocks * MCLK = MCLK = 3MHz * ACLK = REFO/4 = 32Khz */ MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); /* Initializing ADC (MCLK/1/1) */ MAP_ADC14_enableModule(); MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1, 0); /* Configuring GPIOs (5.5 A0) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); /* Configuring ADC Memory */ MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Configuring Timer_A in continuous mode and sourced from ACLK */ MAP_Timer_A_configureContinuousMode(TIMER_A0_MODULE, &continuousModeConfig); /* Configuring Timer_A0 in CCR1 to trigger at 16000 (0.5s) */ MAP_Timer_A_initCompare(TIMER_A0_MODULE, &compareConfig); /* Configuring the sample trigger to be sourced from Timer_A0 and setting it * to automatic iteration after it is triggered*/ MAP_ADC14_setSampleHoldTrigger(ADC_TRIGGER_SOURCE1, false); /* Enabling the interrupt when a conversion on channel 1 is complete and * enabling conversions */ MAP_ADC14_enableInterrupt(ADC_INT0); MAP_ADC14_enableConversion(); /* Enabling Interrupts */ MAP_Interrupt_enableInterrupt(INT_ADC14); MAP_Interrupt_enableMaster(); /* Starting the Timer */ MAP_Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_CONTINUOUS_MODE); /* Going to sleep */ while (1) { MAP_PCM_gotoLPM0(); } }
void init_timer32_0(void) { MAP_Timer32_initModule(TIMER32_0_MODULE, TIMER32_PRESCALER_256, TIMER32_32BIT, TIMER32_PERIODIC_MODE); Timer32_setCount(TIMER32_0_MODULE,6000000); Timer32_enableInterrupt(TIMER32_0_MODULE); MAP_Interrupt_enableInterrupt(INT_T32_INT1); //MAP_Interrupt_enableMaster(); Timer32_startTimer(TIMER32_0_MODULE, true); }
int main(void) { uint32_t ii; /* Disabling the Watchdog */ MAP_WDT_A_holdTimer(); xferIndex = 0; /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function, * (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL). */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* Configuring GPIO P1.0 to be an input. As the GPIO is pulled up by the * master, when the port is set to an input the pull-up defaults and the * pin is high. When the interrupt is asserted, we set the GPIO to an * output low and cause the interrupt to occur. */ MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN1); MAP_GPIO_setAsInputPin(GPIO_PORT_P1, GPIO_PIN0); /* eUSCI I2C Slave Configuration */ MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_1, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); /* Enable the module and enable interrupts */ MAP_I2C_enableModule(EUSCI_B0_MODULE); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); /* Sleeping while not in use */ while (1) { /* Delaying between transactions */ for(ii=0;ii<4000;ii++); /* Initiating the read from the master by asserting our GPIO */ MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0); MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_Interrupt_enableSleepOnIsrExit(); MAP_PCM_gotoLPM0InterruptSafe(); } }
int main(void) { /* Disabling the Watchdog */ MAP_WDT_A_holdTimer(); xferIndex_0 = 0; xferIndex_1 = 0; /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function, * (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL). */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* eUSCI I2C Slave Configuration */ /* Slave Address 1 (0x48) */ MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_1, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); /* Slave Address 1 (0x49) */ MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_2, EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); /* Set in receive mode */ MAP_I2C_setMode(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_MODE); /* Enable the module and enable interrupts */ MAP_I2C_enableModule(EUSCI_B0_MODULE); MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT1); MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT1); MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); MAP_Interrupt_enableMaster(); /* Sleeping while not in use */ while (1) { MAP_PCM_gotoLPM0(); } }
//----------------------------------------------------------------------- int RF_Init(void) { int err = 0; //Setting RGB LED as output MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); //Set P6.1 to be the pin interupt MAP_GPIO_setAsInputPin(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1); //Enable the gpio interupt MAP_Interrupt_enableInterrupt(INT_PORT6); MAP_Interrupt_enableMaster(); /* Initial values for nRF24L01+ library config variables */ rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit rf_addr_width = (uint8_t)PACKET_SIZE; rf_speed_power = RF24_SPEED_MIN | RF24_POWER_MAX; rf_channel = 120; msprf24_init(); // All RX pipes closed by default msprf24_set_pipe_packetsize(0, (uint8_t)PACKET_SIZE); msprf24_open_pipe(0, 1); // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs // Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31) msprf24_standby(); user = msprf24_current_state(); memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5); // addr[0] = 0xDE; addr[1] = 0xAD; addr[2] = 0xBE; addr[3] = 0xEF; addr[4] = 0x00; 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. msprf24_activate_rx(); return err; }
//------------------------------------------------------------------------------ int InitFunction(void) { int err = NONE; MAP_WDT_A_holdTimer(); /* Configuring P6.7 as an input. P1.0 as output and enabling interrupts */ // MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); //Setting RGB LED as output MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); //Set P6.1 to be the pin interupt MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1); MAP_Interrupt_enableInterrupt(INT_PORT6); MAP_Interrupt_enableMaster(); return err; }
/* * See the serial2.h header file. */ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned long uxQueueLength ) { /* Create the queue used to hold received characters. NOTE THE COMMENTS AT THE TOP OF THIS FILE REGARDING THE USE OF QUEUES FOR THIS PURPSOE. */ xRxQueue = xQueueCreate( uxQueueLength, sizeof( char ) ); configASSERT( xRxQueue ); /* Use the library functions to initialise and enable the UART. */ MAP_UART_initModule( EUSCI_A0_MODULE, &xUARTConfig ); MAP_UART_enableModule( EUSCI_A0_MODULE ); MAP_UART_clearInterruptFlag( EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT | EUSCI_A_UART_TRANSMIT_INTERRUPT ); MAP_UART_enableInterrupt( EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT ); /* The interrupt handler uses the FreeRTOS API function so its priority must be at or below the configured maximum system call interrupt priority. configKERNEL_INTERRUPT_PRIORITY is the priority used by the RTOS tick and (should) always be set to the minimum priority. */ MAP_Interrupt_setPriority( INT_EUSCIA0, configKERNEL_INTERRUPT_PRIORITY ); MAP_Interrupt_enableInterrupt( INT_EUSCIA0 ); /* Only one UART is supported so the handle is not used. */ return ( xComPortHandle ) 0; }
void DWire::_initSlave(void) { // Init the pins MAP_GPIO_setAsPeripheralModuleFunctionInputPin(modulePort, modulePins, GPIO_PRIMARY_MODULE_FUNCTION); // initialise driverlib MAP_I2C_initSlave(module, slaveAddress, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); // Enable the module MAP_I2C_enableModule(module); // Enable the module and enable interrupts MAP_I2C_enableModule(module); MAP_I2C_clearInterruptFlag(module, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_STOP_INTERRUPT | EUSCI_B_I2C_TRANSMIT_INTERRUPT0); MAP_I2C_enableInterrupt(module, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_STOP_INTERRUPT | EUSCI_B_I2C_TRANSMIT_INTERRUPT0); //MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableInterrupt(intModule); MAP_Interrupt_enableMaster(); }
int main(void) { volatile uint32_t ii; /* Disabling the Watchdog */ MAP_WDT_A_holdTimer(); /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function, * (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL). */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); sendStopCondition = false; sendToSlaveAddress2 = false; /* Initializing I2C Master to SMCLK at 400kbs with no autostop */ MAP_I2C_initMaster(EUSCI_B0_MODULE, &i2cConfig); /* Specify slave address. For start we will do our first slave address */ MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_1); /* Set Master in receive mode */ MAP_I2C_setMode(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_MODE); /* Enable I2C Module to start operations */ MAP_I2C_enableModule(EUSCI_B0_MODULE); /* Enable and clear the interrupt flag */ MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT); //Enable master Receive interrupt MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); while (1) { /* Load Byte Counter */ TXByteCtr = 4; /* Making sure the last transaction has been completely sent out */ while (MAP_I2C_masterIsStopSent(EUSCI_B0_MODULE) == EUSCI_B_I2C_SENDING_STOP); /* Sending the initial start condition for appropriate * slave addresses */ if(sendToSlaveAddress2) { MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_2); } else { MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_1); } MAP_I2C_masterSendMultiByteStart(EUSCI_B0_MODULE, TXData++); while(sendStopCondition == false) { /* Go to sleep while data is being transmitted */ MAP_Interrupt_enableSleepOnIsrExit(); MAP_PCM_gotoLPM0InterruptSafe(); } sendStopCondition = false; } }
Void uartFxn(UArg arg0, UArg arg1) { int8_t input[] = " "; LcdObj lcd_message; int index = 0; for(index = 0; index < 15; index++) { lcd_message.buffer[index] = ' '; } lcd_message.position = 1; UART_Handle uart; UART_Params uartParams; /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 9600; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) { System_abort("Error opening the UART"); } Semaphore_pend(start_data_semaphore, BIOS_WAIT_FOREVER); // wait on button semaphore //send this char for handshaking with PC int8_t prompt = 65; UART_write(uart, &prompt, 1); int total_x = 0; int total_y = 0; int total_z = 0; int average_x = 0; int average_y = 0; int average_z = 0; int counter = 0; int rx = 0; while (1) { UART_read(uart, &input, 2); if(input[0] == '$' && input[1] == '$') { P2OUT &= ~BIT1; P1OUT |= BIT0; BIOS_exit(1); } rx = (int)input[1]; if(input[0] == '-') { rx = 0 - rx; } total_x = total_x + rx; UART_read(uart, &input, 2); if(input[0] == '$' && input[1] == '$') { P2OUT &= ~BIT1; P1OUT |= BIT0; BIOS_exit(1); } rx = (int)input[1]; if(input[0] == '-') { rx = 0 - rx; } total_y = total_y + rx; UART_read(uart, &input, 2); if(input[0] == '$' && input[1] == '$') { P2OUT &= ~BIT1; P1OUT |= BIT0; BIOS_exit(1); } rx = (int)input[1]; if(input[0] == '-') { rx = 0 - rx; } total_z = total_z + rx; /* if((counter % 3) == 0) { total_x = total_x + rx; } else if ((counter % 3) == 1) { total_y = total_y + rx; } else { total_z = total_z + rx; }*/ counter++; if(counter > 50) { average_x = total_x/counter; average_y = total_y/counter; average_z = total_z/counter; combine_ints_to_string(average_x, average_y, average_z, 15,lcd_message.buffer); counter = 0; total_x = 0; total_y = 0; total_z = 0; lcd_message.position = 1; Mailbox_post(LCD_Mbx, &lcd_message, BIOS_WAIT_FOREVER); } MAP_Interrupt_enableInterrupt(INT_ADC14); } }
void StartTimerA0_0() { MAP_Interrupt_enableInterrupt(INT_TA0_0); MAP_Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE); }