MSP432 EVM - SPI테스트
[MSP432 EVM] 보드의 SPI 포트는 UCB1 P6.2, P6.3, P6.4, P6.5에 할당되어 있다. SPI로 핀을 할당하기 위해 코드에서 아래와 같이 설정해 주면 된다.
void PinMuxConfig(void)
{
//
// Configure P6.3 for EUSCI_B1_SPI_I2C EUSCI_B1_SPI_I2C.CLK
//
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
//
// Configure P6.4 for EUSCI_B1_SPI_I2C EUSCI_B1_SPI_I2C.SIMO
//
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);
//
// Configure P6.5 for EUSCI_B1_SPI_I2C EUSCI_B1_SPI_I2C.SOMI
//
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION);
//
// Configure P6.2 for EUSCI_B1_SPI_I2C EUSCI_B1_SPI_I2C.STE
//
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);
}
MSP432 SPI 초기화 함수
/* SPI Master Configuration Parameter */
const eUSCI_SPI_MasterConfig spiMasterConfig =
{
EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
3000000, // SMCLK = DCO = 3MHZ
500000, // SPICLK = 500khz
EUSCI_B_SPI_MSB_FIRST, // MSB First
EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, // Phase
EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH, // High polarity
EUSCI_B_SPI_3PIN // 3Wire SPI Mode
};
void SPI0_Init(void)
{
/* Selecting SPI mode */
PinMuxConfig();
/* Configuring SPI in 3wire master mode */
SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig);
/* Enable SPI module */
SPI_enableModule(EUSCI_B0_BASE);
/* Enabling interrupts */
SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
Interrupt_enableInterrupt(INT_EUSCIB0);
Interrupt_enableSleepOnIsrExit();
TXData = 0x01;
}
MSP432 SPI 송수신 함수
unsigned char SPI0_WriteReadByte(unsigned char Data)
{
while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)));
RXData = SPI_receiveData(EUSCI_B0_BASE);
/* Send the next data packet */
SPI_transmitData(EUSCI_B0_BASE, Data);
}