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.

SPI 'master' send any data 'slave' always load with "0xff" data in MSP430f6779

here is my code,,,,,,,when i load   UCA0TXBUF = 0x01; same time  UCA0RXBUF  load with "0xff".what is problem with dat..........

is my UCA0BR0 and UCA0BR1  problem .............................

is my clk frequency problem...................i m setting  clk frequency 16MHz and baudrate of 9600  so,  UCA0BR0 =130 and UCA0BR1  =6.........

here is my code.....and plz tell me cs value should high or low...............................

#include <msp430.h>
#include "math.h"

unsigned int received_ch = 0;


void set_clk();
int SerialPortInit(unsigned long ulBaudRate);
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P5OUT |= BIT0;
P5DIR |= BIT0;   //  for cs................



P3SEL0 |= BIT0 | BIT1 | BIT2; // Set P3.0,P3.1,P3.2 to non-IO

set_clk();   //.......................................clk set to 16Mhz    and 9600 br

// Setup eUSCI_A0
UCA0CTLW0 |= UCSWRST; // **Put state machine in reset**
UCA0CTLW0 |= UCMST | UCSYNC | UCMSB ; // 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCA0CTLW0 |= UCSSEL_2; // SMCLK
UCA0BRW_L = 130; // /2
UCA0BRW_H = 6; //
UCA0MCTLW = 0; // No modulation
UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE = UCRXIE;


//UCCKPH=Clock phase select,UCMSB=MSB first select. Controls the direction of the receive and transmit shift register
//UCMST =Master mode select, 0b = Slave mode,1=Master mode select
//UCSYNC=Synchronous mode enable... 0b = Asynchronous mode...........1b = Synchronous mode



P5OUT &= ~ BIT0; // Select Device


__delay_cycles(1000);






while(!(UCA0IFG & UCTXIFG)); // USCI_A0 TX buffer ready?

//UCTXIFG=Transmit interrupt flag. UCTXIFG is set when UCBxTXBUF empty
UCA0TXBUF = 0x01; // Send 0x01 over SPI to Slave....................................................................................here main prob???? RXBUFF always load with "0xff"

__delay_cycles(10000000);

__bis_SR_register(LPM4_bits + GIE);


}



void set_clk()
{

UCSCTL3 |= SELREF_2; // select .... REFOCLK
UCSCTL4 |= SELA_2; // REFOCLK.....use of Aclk for smclk =SELS_2


__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 | 487; // Set DCO Multiplier for 8MHz.....making of 16Mhz
// (N + 1) * FLLRef = Fdco
// (243 + 1) * 32768 = 8MHz //(487+ 1) * 32768 = 16MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop

// Worst-case settling time for the DCO when the DCO range bits have been
// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
// UG for optimization.
// 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
__delay_cycles(500000);
// __delay_cycles(76563); //for 2.45Mhz

// Loop until XT1, XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); //XT2 oscillator fault flag|XT1 oscillator fault flag|DCO fault flag
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag

}


#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
received_ch = UCA0RXBUF;


break;
case 4:break; // Vector 4 - TXIFG
default: break;
}
}

  • msp430f665x_ucs_03.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    /* --COPYRIGHT--,BSD_EX
    * Copyright (c) 2012, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    *******************************************************************************
    *
    * MSP430 CODE EXAMPLE DISCLAIMER
    *
    * MSP430 code examples are self-contained low-level programs that typically
    * demonstrate a single peripheral function or device feature in a highly
    * concise manner. For this the code may rely on the device's power-on default
    * register values and settings such as the clock configuration and care must
    * be taken when combining code from several examples to avoid potential side
    * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
    * for an API functional library-approach to peripheral configuration.
    *
    * --/COPYRIGHT--*/
    //******************************************************************************
    // MSP430F665x Demo - Software Toggle P1.1 with 12MHz DCO
    //
    // Description: Toggle P1.1 by xor'ing P1.1 inside of a software loop.
    // ACLK is brought out on pin P1.0, SMCLK = MCLK on P3.4.
    // PMMCOREV = 1 to support up to 12MHz clock
    //
    // ACLK = REFO = 32kHz, MCLK = SMCLK = 12MHz
    //
    // MSP430F665x
    // -----------------
    // /|\| |
    // | | P1.0|-->ACLK
    // --|RST |
    // | P3.4|-->SMCLK = MCLK
    // | |
    // | P1.1|-->Port Pin
    // Note:
    // In order to run the system at up to 12MHz, VCore must be set at 1.6V
    // or higher.
    //
    // P. Thanigai
    // Texas Instruments Inc.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Hello Hitesh,

    I am currently investigating the behavior you've stated.  Meanwhile there are some other issues that need to be addressed:

    1. Baud rate concerns UART mode, not SPI, so your UCA0BRW is simply a bit clock prescalar and not a modulation control.

    2. Please refer to Figure 3 of the device datasheet.  You must increase your PMMCOREV settings up to at least 2 (in order, or level-by-level, and with the proper SVM & SVS changes) in order to operate at a 16 MHz system frequency.  An example of how this can be done is attached.

    3. You are using 3-wire SPI mode so the CS pin is not necessarily important regarding USCI master behavior, it is typically low for active and high for inactive.

    Regards, Ryan

  • Hitesh,

    Do you have a slave device connected? If the MISO line is floating instead of being actively pulled low by the slave then the input could be erroneously read as 0xFF. You can also test this by manually grounding the MISO line.

    Regards,
    Ryan

**Attention** This is a public forum