Part Number:MSP432P401R
Hello,
I need to send and receive data via SPI (3-Wire).
In my setup MSP432 board is master, clock settings, first byte and clock polarity dont make difference now.
I've tryed 2 ways to use SPI:
1) Bare-bones
. . . void SPI_WriteByte(unsigned char Data) { while (!(UCB0IFG&UCTXIFG)); UCB0TXBUF = Data; } unsigned char SPI_ReadByte(void) { unsigned char Data; while (!(UCB0IFG&UCRXIFG)); //tryed to put this after "Data = UCB0RXBUF", or delete complitely - result same. Data = UCB0RXBUF; //UCA3IFG &= ~UCRXIFG; return Data; } int main(void){ . . . P1SEL0 |= BIT5 | BIT6 | BIT7; //Set to second function. UCB0CTLW0 |= UCSWRST; // **Put state machine in reset** UCB0CTLW0 |= UCMST|UCSYNC|UCMSB; // 3-pin, 8-bit SPI master // Clock polarity high, MSB UCB0CTLW0 |= UCSSEL__ACLK; // ACLK UCB0BR0 = 0x01; // /2,fBitClock = fBRCLK/(UCBRx+1). UCB0BR1 = 0; // UCB0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine** while(1) { SPI_WriteByte(0x55); //This works good. clock generated, data sent. SPI_ReadByte(); //There clock not generated at all. Just passing or CPU locks there. } . . . }
2) Using driverlib
. . . // Just wraps void SPI_WriteByte(byte Data) { SPI_transmitData(EUSCI_B0_MODULE, Data); } byte SPI_ReadByte(void) { return SPI_receiveData(EUSCI_B0_MODULE); } const eUSCI_SPI_MasterConfig spiMasterConfig = { EUSCI_B_SPI_CLOCKSOURCE_ACLK, // ACLK Clock Source 32768, // ACLK = LFXT = 32.768khz 500000, // SPICLK = 500khz EUSCI_B_SPI_MSB_FIRST, // MSB First EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, // Phase EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // High polarity EUSCI_B_SPI_3PIN // 3Wire SPI Mode }; int main() { . . . CS_setExternalClockSourceFrequency(32768, 0); CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12); CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); //CS_startLFXT(CS_LFXT_DRIVE0); GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); SPI_initMaster(EUSCI_B0_MODULE, &spiMasterConfig); SPI_enableModule(EUSCI_B0_MODULE); while(1) { SPI_WriteByte(0x55); //Again, works as expected. SPI_ReadByte(); //No clock. Does nothing to CLK line. } }
SPI_WriteByte works as expected in both cases. But i completely stuck with SPI_ReadByte function. SPI Master should generate clock on read, but this never happens(Im using scope to inspect lines.). Ive tryed to enable interrupts, change clock sources, but nothing seems to help. Both of this codes is overwritten examples from IAR repository. Mostly ive only changed A3/A0 to B0.
For me this is complitely mystery why clock do not generated at one case, but genereted on other. Im pretty new to MSP and ARM in general. Moved from AVR and this not obvios for me.