Dear TI community,
I've read more answers about this topic but I think none fit my problem. I'm using MSP430G2553 and trying to get working UART (UCA0) and SPI (UCB0) simultaneously. I've made initialization functions uartInit() and spiInit(). If I run only uartInit(), UART works fine - same as if i run only spiInit(), then SPI works OK.
If I run both of them, there are only some mess on MISO MOSI and SCK pins. Am I missing something?
I'm very sorry If I missed some topic with solution on this, I'm stuck here few hours. Thank you for your comments.
LJ
--------------------------- CODE ------------------------------- functions.c
void uartInit()
{
// reset UCA0 peripheral
UCA0CTL1 |= UCSWRST;
UCA0CTL1 |= 0x02; // SMCLK
UCA0BR0 |= 104; // ~9600bd
UCA0BR1 = 0;
UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5
P1SEL = BIT1 | BIT2; // set P1.2 and P1.1 to UART
P1SEL2 = BIT1 | BIT2;
UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine
// UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt
}
void spiInit()
{
// reset UCB0 peripheral
UCB0CTL1 |= UCSWRST;
UCB0CTL1 |= 0x02; // SMCLK
UCB0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCB0BR0 |= 0x02; // 500kHz
UCB0BR1 = 0;
P1SEL = BIT7 | BIT6 | BIT5 ; // set P1.5 P1.6 P1.7 modes to SPI
P1SEL2 = BIT7 | BIT6 | BIT5 ;
P1DIR |= BIT4;
P2DIR |= BIT0; // CS
P2OUT |= BIT0;
UCB0CTL1 &= ~UCSWRST; // Initialize USCI state machine
}
------------------------------------------ main.c
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
DCOCTL = 0; // Select lowest DCOx and MODx settings<
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
uartInit();
spiInit();
..... etc