//******************************************************************************
// MSP432P401 Demo - eUSCI_B0 I2C Master TX bytes to Multiple Slaves
//
// Description: This demo connects two MSP432's via the I2C bus.
// The master transmits to 4 different I2C slave addresses 0x0A,0x0B,0x0C&0x0D.
// Each slave address has a specific related data in the array TXData[].
// At the end of four I2C transactions the slave address rolls over and begins
// again at 0x0A.
//
// Use with msp432p401_euscia0_i2c_multislave.c
//
// /|\ /|\
// MSP432P401 10k 10k MSP432P401
// slave | | master
// ----------------- | | -----------------
// | P1.6/UCB0SDA||P1.6/UCB0SDA |
// | | | | |
// | | | | |
// | P1.7/UCB0SCL||P1.7/UCB0SCL |
// | | | |
//
// Wei Zhao
// Texas Instruments Inc.
// June 2014
// Built with Code Composer Studio V6.0
//******************************************************************************
#include "msp.h"
#include
uint8_t TXData[]= {0xA1,0xB1,0xC1,0xD1}; // Pointer to TX data
uint8_t SlaveAddress[]= {0x0A,0x0B,0x0C,0x0D};
uint8_t TXByteCtr;
uint8_t SlaveFlag = 0;
int main(void)
{
volatile uint32_t i;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure Pins for I2C
P1SEL0 |= BIT6 | BIT7; // I2C pins
__enable_interrupt();
NVIC_ISER0 = 1
基于固件库的编程,目前比较流行的M4程序编程方法
/*******************************************************************************
* MSP432 I2C - EUSCI_B0_MODULE I2C Slave RX multiple bytes from MSP432 Master
*
* Description: This demo connects two MSP432 's via the I2C bus. The master
* transmits to the slave. This is the slave code. The interrupt driven
* data reception is demonstrated using the USCI_B0 RX interrupt. Data is
* stored in the RXData array.
*
* /|\ /|\
* MSP432P401 10k 10k MSP432P401
* slave | | master
* ----------------- | | -----------------
* | P1.6/UCB0SDA|<-|----+->|P1.6/UCB0SDA |
* | | | | |
* | | | | |
* | P1.7/UCB0SCL|<-+------>|P1.7/UCB0SCL |
* | | | |
*
* Author: Timothy Logan
******************************************************************************/
/* DriverLib Includes */
#include "driverlib.h"
/* Standard Includes */
#include
#include
/* Application Defines */
#define SLAVE_ADDRESS 0x48
#define NUM_OF_RX_BYTES 4
/* Statics */
static volatile uint8_t RXData[NUM_OF_RX_BYTES];
static volatile uint32_t xferIndex;
int main(void)
{
/* 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);
/* eUSCI I2C Slave Configuration */
MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0,
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);
MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);
MAP_Interrupt_enableSleepOnIsrExit();
MAP_Interrupt_enableInterrupt(INT_EUSCIB0);
MAP_Interrupt_enableMaster();
/* Sleeping while not in use */
while (1)
{
MAP_PCM_gotoLPM0();
}
}
/******************************************************************************
* 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 */
if (status & EUSCI_B_I2C_RECEIVE_INTERRUPT0)
{
RXData[xferIndex++] = MAP_I2C_slaveGetData(EUSCI_B0_MODULE);
/* Resetting the index if we are at the end */
if (xferIndex == NUM_OF_RX_BYTES)
xferIndex = 0;
}
}