Part Number: MSP432P401R
I will give down below the code I use for sending over the SPI.
I need to send very quickly bytes to the CC1200 chip. And because of that, I work without interrupts and I only watch the flag. As soon as it goes up, I send the next byte over the SPI.
First I pull STE low, then I wait for the CC1200 to be ready(wait for the SOMI to go high) and then I send bytes over the SPI. At the end, I wait for the sending to be finished and I pull STE high.
There are two problems:
1. Using the SPI is Busy function doesn't seem to work so I look at the Busy bit manually.
2. Sometimes the SPI doesn't want to set the Interrupt flag for the transmit buffer. After some transmit the flag goes down and doesn't come back up.
This error occurs rarely and I can't find why it happens.
#define CC1200 EUSCI_B0_BASE uint8_t CC1200_Burst_Write(uint8_t* inputBuffer, uint8_t startingAddress, uint8_t length) { int32_t i; uint8_t statusByte; CC1200_Select_Module(); /* Command byte that says burst write from starting address */ CC1200_Transmit_Byte(startingAddress | CC1200_WRITE_BURST); statusByte = CC1200_Receive_Byte(); for(i = 0; i<length; i++) { CC1200_Transmit_Byte(inputBuffer[i]); } CC1200_Deselect_Module(); return statusByte; } static void CC1200_Select_Module() { /* Clear receive interrupt status */ EUSCI_B_SPI_clearInterruptFlag(CC1200_SPI, CC1200_SPI_RECEIVE_INTERRUPT); /* Pull chip select down and wait until SOMI goes down */ MAP_GPIO_setOutputLowOnPin(CC1200_SPI_PORT, CC1200_SPI_STE); while (MAP_GPIO_getInputPinValue(CC1200_SPI_PORT, CC1200_SPI_MISO)); } static void CC1200_Deselect_Module() { /* Wait for the SPI to finish transfer to deselect the module */ while (UCB0STATW & 1); /* After ending transfer, pull chip select up */ MAP_GPIO_setOutputHighOnPin(CC1200_SPI_PORT, CC1200_SPI_STE); } static void CC1200_Transmit_Byte(uint8_t byte) { /* Wait for transmit buffer to be empty and transmit byte */ while (!(EUSCI_B_SPI_getInterruptStatus(CC1200_SPI, CC1200_SPI_TRANSMIT_INTERRUPT))); EUSCI_B_SPI_transmitData(CC1200_SPI, byte); } static uint8_t CC1200_Receive_Byte() { /* Wait for receive flag to read receive register */ while (!(EUSCI_B_SPI_getInterruptStatus(CC1200_SPI, CC1200_SPI_RECEIVE_INTERRUPT))); return EUSCI_B_SPI_receiveData(CC1200_SPI); }