This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC430F5133: SPI communication

Part Number: CC430F5133
Other Parts Discussed in Thread: CC1101, CC430F5137

Hi Team,

We would like to ask your help regarding our customer's inquiry below.

We are currently working on a SPI-UART bridge utilizing the MSP430F5133. During testing we are not able to properly communicate with the RHD2132 and received the information from the desired converted channel. During the same process we are also interested in sending the information collected to MSP430-CCRF for data collection. We attempted multiple configurations with the PM_UCB0CLK as the clock and the current built utilizing the SCLK output as the direct SPI clock. The code we are utilizing is attached as well as the RHD2132 data sheet.

A final question would be related to the best optimized way to collect the information from an msp430 board, such as export to csv or xls.

Optrode_Sense_Schematic.pdf

Intan_RHD2000_series_datasheet.pdf

Eval_Flash.c
#include <msp430.h>
#include <stdint.h>

void initialize_clk(void);                      // Function: Clock Initialize
void initialize_pin(void);                      // Function: Pin Initialize
void calibrate_intan(void);                     // Function: Calibration
void wait_intan(uint8_t count);                 // Function: Delay MSP430 for CS
uint16_t convert_intan(uint8_t channel);        // Function: 16-bit
uint16_t transfer_16_bit_MOSI(uint16_t command);// Function: Sends command, receives result

int main(void)
{
    uint8_t j =1;                               // Shifting variable
    uint16_t data[40];                          // Values stored from transfer

    WDTCTL = WDTPW | WDTHOLD;                   // stop watchdog timer

    initialize_pin();                           // Initialize pin configuration
    initialize_clk();                           // Initialize clock configuration
    calibrate_intan();                          // Calibration

    data[0] = convert_intan(0);                 // Initial data transfer

    while(1)
    {
        data[j] = convert_intan(63);
        j++;
        if(j == 31)
            {j = 0;}
    }
    return 0;
}

void initialize_pin(void)
{
    PMAPPWD = 0x02D52;                          // Get write-access to port mapping register
    P1MAP2 = PM_UCB0SOMI;                       // Map UCB0SOMI output to P1.2
    P1MAP3 = PM_UCB0SIMO;                       // Map UCB0SIMO output to P1.3
    P2MAP6 = PM_UCA0RXD;                        // Map UCA0RXD output to P2.6
    P2MAP7 = PM_UCA0TXD;                        // Map UCA0TXD output to P2.7
    PMAPPWD = 0;                                // Lock port mapping registers

    P1DIR |= BIT4;                              // Set as output pin    [1.4:CS]
    P1DIR |= BIT2 + BIT3;                       // Set UCIB_0           [1.2:SIMO][1.3:MOSI]
    P2DIR |= BIT7;                              // Set as TX output     [2.7:DMAE0]
    P3DIR |= BIT7;                              // Set as output        [3.7:SMCLK]

    P1OUT &= ~BIT4;                             // Sets CS high
    P1SEL |= BIT2 + BIT3;                       // Enable SPI function
    P2SEL |= BIT6 + BIT7;                       // Enable UART function
    P3SEL |= BIT7;                              // Enable SPI CLK
    P5SEL |= 0x03;                              // Enable XT1 pins
}

void initialize_clk(void)
{
    UCSCTL3 |= SELREF_2;                        // Set DCO FLL reference = REFO
    UCSCTL4 |= SELA_2;                          // Set ACLK = REFO

    __bis_SR_register(SCG0);                    // Disable the FLL control loop
    UCSCTL0 = 0x0000;                           // Set lowest possible DCOx, MODx
    UCSCTL1 = DCORSEL_5;                        // Select DCO range 16MHz operation
    UCSCTL2 = FLLD_1 +  249;                    // Set DCO Multiplier for 8MHz
                                                // (N + 1) * FLLRef = Fdco
                                                // (249 + 1) * 32768 = 8192000Hz
                                                // Set FLL Div = fDCOCLK/2
    __bic_SR_register(SCG0);                    // Enable the FLL control loop

    UCA0CTL1 |= UCSWRST;                        // **Put state machine in reset**
    UCA0CTL1 |= UCSSEL_1;                       // CLK = ACLK
    UCA0BR0 = 0x03;                             // 32k/9600 - 3.41
    UCA0BR1 = 0x00;                             //
    UCA0MCTL = 0x06;                            // Modulation
    UCA0CTL1 &= ~UCSWRST;                       // **Initialize USCI state machine**
    UCA0IE |= UCRXIE + UCTXIE;                  // enable interrupt flags

    UCB0CTL1 |= UCSWRST;                        // Set in reset state so that config can be added
    UCB0CTL0 = UCMST+UCSYNC+UCCKPL+UCMSB;       // 3-pin, 8-bit SPI master
    UCB0CTL1 = UCSSEL_2;                        // SMCLK
    UCB0BR0 = 0x02;                             // SPI same clock as SMCLK/1 (8Mhz)
    UCB0BR1 = 0x00;                             //
    UCB0CTL1 &= ~UCSWRST;                       // **Initialize USCI state machine** Effectively starting SPI communication, now only need to pull CS low when sending data
    UCB0IE |= UCRXIE + UCTXIE;                  // enable interrupt flags

    do
    {
        UCSCTL7 &= ~(XT1LFOFFG + DCOFFG);       // Clear XT2,XT1,DCO fault flags
        SFRIFG1 &= ~OFIFG;                      // Clear fault flags
        __delay_cycles(100000);                 // Delay for Osc to stabilize
    }while (SFRIFG1&OFIFG);                     // Test oscillator fault flag

}

void calibrate_intan(void)
{
    transfer_16_bit_MOSI(0x5500);               // Calibrate on datasheet is command: (0101  0101  0000  0000) which is equivalent to  0x5500
    wait_intan(9);                              // Waits for calibration to complete
}

void wait_intan(uint8_t count)
{
    for(;count>0;count--)
    {
        P1OUT &= ~BIT4;                         // Sets CS high
        _delay_cycles(31);                      // Delay for CS reset
        P1OUT |= BIT4;                          // Sets CS low
    }
}

uint16_t convert_intan(uint8_t channel)
{
    uint16_t command;                           // 16 bit senting
    uint8_t static const convert_mask = 0x00;   // Mask to write to keep "00" at MSBits

    command = (((convert_mask | channel) << 8 ) | (0x00));      // Creates command

    return transfer_16_bit_MOSI(command);
}

uint16_t transfer_16_bit_MOSI(uint16_t command)
{
    uint8_t hi = ((command>>8)&0xff);
    uint8_t lo = ((command>>0)&0xff);
    uint8_t bytes_RX_buffer[2];                 // Stores received data

    P1OUT |= BIT4;                              // Sets CS low

    while (!(UCB0IFG&UCTXIFG));                 // USCI_B0 TX buffer ready?
    {UCB0TXBUF = hi;}                           // Send first 8 bits of command over SPI to Slave
    while (!(UCB0IFG&UCTXIFG));                 // USCI_B0 TX buffer ready?
    {UCB0TXBUF = lo;}                           // Send last 8 bits of command over SPI to Slave

    wait_intan(2);

    while (!(UCB0IFG&UCRXIFG));                 // USCI_B0 RX Received?
    {bytes_RX_buffer[1] = UCB0RXBUF;}           // Store received data
    while (!(UCB0IFG&UCRXIFG));                 // USCI_B0 RX Received?
    {bytes_RX_buffer[0] = UCB0RXBUF;}           // Store received data

    P1OUT &= ~BIT4;                             // Sets CS high

    while (!(UCA0IFG&UCTXIFG));                 // USCI_B0 TX buffer ready?
    {UCA0TXBUF = bytes_RX_buffer[0];}           // Send first 8 bits of command over UART
    while (!(UCA0IFG&UCTXIFG));                 // USCI_B0 TX buffer ready?
    {UCA0TXBUF = bytes_RX_buffer[1];}           // Send last 8 bits of command over UART

    return ((bytes_RX_buffer[1] << 8) | bytes_RX_buffer[0]);
}

Regards.

Danilo