Hi there,
Recently I got a project working with the MSP430F2013, using SPI over USI to read from an SD card. I am now trying to port this project to an MSP430F249, to take advantage of more I/O, and with some minor declaration tweaks, everything seems to be working except for the two primary SPI functions. The functions spiSendByte(constant unsigned char data) and MMC_initSPI(void) are set up to use SPI through USI, and I haven't been able to find any guides as to how to rewrite these using USCI. This seems to be necessary because most of the registers referenced in USI don't have direct equivalents in USCI. Can anyone help me figure out how to write these utilizing USCI, or point me in the direction of an appropriate example? I know this chip has 4 USCI, and all of them are available to me for this, everything else is much easier to move around. Thank you in advance!
The code of the two functions follows:
unsigned char spiSendByte(const unsigned char data)
{
while (!(USICTL1&USIIFG)); // Wait for RX to finish
USISRL=data;
USICNT = 8; // send 8 bits of data
while (!(USICTL1&USIIFG)); // Wait for RX to finish
return (USISRL); // Store data
}
void MMC_initSPI(void){
//chip select
SD_CSn_PxDIR|=SD_CSn_PIN;
SD_CSn_PxOUT|=SD_CSn_PIN;
USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
//USICTL1 |= USICKPH; // USICKPH; // Counter interrupt, flag remains set
USICKCTL = USIDIV_0 + USISSEL_2 + USICKPL; // /4 SMCLK + USICKPL +
USICTL0 &= ~USISWRST; // USI released for operation
}