0
\$\begingroup\$

I'm currently working with MSP430FR2433 Micro. I want to interface this micro with the following modules:

Purpose: The user enters a 4-digit code (say 7777) via the Keypad. The micro should read the code, then compare it, then if a match should turn on LED1 (on the dev board), and sent the entered code via UART to RealTerm software.

Problem: I'm very positive that the problem is with the clock config.

Issue: When I turn ON UART, SPI doesn't work. When I turn OFF Uart, SPI works.

Datasheets: https://www.ti.com/product/MSP430FR2433

Note: When I say doesn't work, the following happens:

  • My SPI is connected to an LCD screen. I'm supposed to see "Code in?" on my LCD via SPI but I got "Co9g0coc". As you can see, the data is corrupted.

  • I'm entering 7777 as a code. I'm supposed to see '7777Z' in the RealTerm. But I see Ÿ777Z or 7·Ÿ7ª or 777·Z.

I have attached the main functions of two different codes. Could you please let me know how to make SPI and UART work?

Uart works SPI doesn't

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

    PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode

    FRAM_counter_ptr = (unsigned int *)FRAM_counter_static;     // always pointed to 1800 location. This is where counter is located
// Configure UART pins
    P2SEL0 |= BIT5 | BIT6;                    // set 2-UART pin as second function

    // Configure UART
    UCA1CTLW0 |= UCSWRST;
    UCA1CTLW0 |= UCSSEL__SMCLK;

    UCA1BR0 = 52;                                    // 8000000/16/9600
    UCA1BR1 = 0x00;
    UCA1MCTLW = 0x4900 | UCOS16 | UCBRF_1;

    UCA1CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
    UCA1IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

    //configure SPI

    P1SEL0 |= BIT4 | BIT5 | BIT6; // set 3-SPI pin as second function

    UCA0CTLW0 |= UCSWRST;                     // **Put state machine in reset**
                                      // 4-pin, 8-bit SPI master

    //UCA1CTLW0 |= UCMST|UCSYNC|UCCKPL|UCMSB|UCMODE_1|UCSTEM;   // Clock polarity high, MSB
    UCA0CTLW0 |= UCMST|UCSYNC|UCMSB|UCMODE_1|UCSTEM;            // Clock polarity low, Clock Phase 1, MSB
    UCA0CTLW0 |= UCSSEL__SMCLK;               // SMCLK
    UCA0BR0 = 0x08;                           // /2,fBitClock = fBRCLK/(UCBRx+1).
    UCA0BR1 = 0;                              //
    UCA0MCTLW = 0;                            // No modulation
    UCA0CTLW0 &= ~UCSWRST;                    // **Initialize USCI state machine**
    UCA0IE |= UCRXIE;                         // Enable USCI_A1 RX interrupt
    //TXData_SPI = 0x01;                            // Holds TX data


    //UCA0IE |= UCTXIE;                      // Enable TX interrupt

SPI works Uart doesn't

    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

    PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode

    FRAM_counter_ptr = (unsigned int *)FRAM_counter_static;     // always pointed to 1800 location. This is where counter is located

       // Configure UART pins
    P2SEL0 |= BIT5 | BIT6;                    // set 2-UART pin as second function

    // Configure UART
    UCA1CTLW0 |= UCSWRST;                     // Put eUSCI in reset
    UCA1CTLW0 |= UCSSEL__SMCLK;
    // Baud Rate calculation
    UCA1BR0 = 0x08;                              // 1000000/115200 = 8.68
    UCA1MCTLW = 0xB700;                       // 1000000/115200 - INT(1000000/115200)=0.68
                                              // UCBRSx value = 0xD6 (See UG)
    UCA1BR1 = 0;
    UCA1CTLW0 &= ~UCSWRST;                    // Initialize eUSCI

P1SEL0 |= BIT4 | BIT5 | BIT6; // set 3-SPI pin as second function

UCA0CTLW0 |= UCSWRST; // **Put state machine in reset**
UCA0CTLW0 |= UCMST|UCSYNC|UCCKPL|UCMSB|UCMODE_0; // 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCA0CTLW0 |= UCSSEL__SMCLK; // SMCLK
UCA0BR0 = 0x01; // /2,fBitClock = fBRCLK/(UCBRx+1).
UCA0BR1 = 0; //
UCA0MCTLW = 0; // No modulation
UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCRXIE;
\$\endgroup\$
1
  • \$\begingroup\$ Those two piecs of code indeed use different configuration settings. Why don't you combine those settings for UCA0 and UCA1 that work? \$\endgroup\$ – CL. Aug 11 '20 at 9:18
0
\$\begingroup\$

I think I found the problem. The SPI apparently was working just fine. It was the LCD that has the issue.

What I didn't take into consideration is that the clock speed changed from 1MHz before to 8Mhz. Its 8 times faster, so I have to increase my delays, like delay after chip select, the transition from command mode to data mode, etc. This is why I was missing 1 or 2 characters.

The initialization of the LCD was also ruined because the delays weren't enough as the clock speed increased 8 times. That's why sometimes, the display wouldn't clear or the cursor wouldn't reset, etc.

I recalculated the delays and ran the code 6 times. Not once I missed any characters. Before that this wasn't the case. I am having a hard time believing this.

Can anyone corroborate my theory? (I'll close the issue after) or is it just luck. I did reduce the delays and saw the same issue pop up.

Thank you

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.