Hello,
I recently got some MSP430F5508s to play around with after moving up from the value line series (G2553 was quite lacking in RAM), and am trying to get the USCI SPI module working. Specifically, I believe I'm having trouble using the Port Mapping Controller. I've configured P4.0 and P4.4 as outputs and as the PM_USCIA1 signals (according to the default pin assignments from the pin diagram). My code is based off the Port Mapping example programs from TI and the SPI configuration I was using with the G2553.
Here's my code to initialize and use the SPI module:
void spi_init(void)
{
//1) Set UCSWRST
UCA1CTL1 |= 1; //UCSWRST = 1
//2) Initialize all USCI registers with UCSWRST=1 (including UCxCTL1)
UCA1CTL1 = (2<<6)|1; //BRCLK = SMCLK, UCSWRST = 1
//Set CLK polarity/phase, MSB first, master mode, 3-pin mode, synchronous
UCA1CTL0 = (CLKPHS<<7)|(CLKPOL<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<1)|1;
//Set clock prescalar value
UCA1BR0 = BR;
//3) Configure ports
sbi(P4DIR,PIN_SS);
sbi(P4OUT,PIN_SS);
// MSP430Fx5xx/x6xx Port Configuration via PMAP
PMAPKEYID = 0x2D52; //PMAPKEY = 0x2D52
PMAPCTL = 0x0002; //Allow reconfiguration
P4MAP5 = PM_UCA1SOMI; //P4.5 (MISO)
P4MAP4 = PM_UCA1SIMO; //P4.4 (MOSI)
P4MAP0 = PM_UCA1CLK; //P4.0 (SCLK)
PMAPKEYID = 0x0000; //PMAPKEY = 0x2D52
sbi(P4SEL,PIN_MISO);
sbi(P4SEL,PIN_MOSI);
sbi(P4SEL,PIN_SCLK);
sbi(P4DIR,PIN_MOSI);
sbi(P4DIR,PIN_SCLK);
//4) Clear UCSWRST via software
UCA0CTL1 &= ~(1); //UCSWRST = 0
}
void spi_out(u08 byte)
{
cbi(P4OUT,PIN_SS);
UCA1TXBUF = byte;
while(UCA0STAT & 0x01); //Wait until USCI not busy
sbi(P4OUT,PIN_SS);
}
I've tested P4.0 and 4.4 as I/O and they can output high/low signals just fine, but as soon as the P4SEL bits are set, the lines appear to become inputs (fall from high level down to 0V with a slow time-constant).
Any help would be appreciated!
- Justin Kenny, KJ6KST
4th year Electrical Engineering student, Cal Poly San Luis Obispo