void DWire::_resetBus( void ) { /* Reset buffers */ *pTxBufferIndex = 0; *pTxBufferSize = 0; *pRxBufferIndex = 0; *pRxBufferSize = 0; /* Reset the module */ MAP_I2C_disableModule( module ); /* Perform bus clear according to I2C-bus Specification and User Manual * (UM10204) section 3.1.16 */ if (this->isMaster( )) { MAP_GPIO_setOutputLowOnPin( modulePort, moduleSCL ); for (uint_fast8_t i = 0; i < 9; i++) { MAP_GPIO_setAsOutputPin( modulePort, moduleSCL ); this->_I2CDelay( ); MAP_GPIO_setAsInputPin( modulePort, moduleSCL ); this->_I2CDelay( ); } MAP_GPIO_setAsPeripheralModuleFunctionInputPin( modulePort, moduleSCL, GPIO_PRIMARY_MODULE_FUNCTION ); } /* Re-enable the module */ MAP_I2C_enableModule( module ); }
/****************************************************************************** * The USCI_B0 data ISR RX vector is used to move received data from the I2C * master to the MSP432 memory. ******************************************************************************/ void euscib0_isr(void) { uint_fast16_t status; status = MAP_I2C_getEnabledInterruptStatus(EUSCI_B0_MODULE); MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE, status); /* RXIFG for Slave Address 1*/ if (status & EUSCI_B_I2C_TRANSMIT_INTERRUPT0) { MAP_I2C_slavePutData(EUSCI_B0_MODULE, TXData[xferIndex++]); /* Resetting the index if we are at the end. Also resetting the GPIO * if we are on the last byte */ if (xferIndex == NUM_OF_RX_BYTES) { MAP_I2C_disableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0); MAP_GPIO_setAsInputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_Interrupt_disableSleepOnIsrExit(); xferIndex = 0; /* IMPORTANT: Clearing out the TX Buffer for the next transfer. * This is required to compensate for the shift/buffer settings * of the I2C module */ MAP_I2C_slavePutData(EUSCI_B0_MODULE, 0); } } }
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 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; }