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.
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; } }
/* --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. // October 2012 // Built with IAR Embedded Workbench Version: 5.40 & CCS V5.2 //****************************************************************************** #include <msp430.h> #include <stdint.h> #define PMM_STATUS_OK 0 #define PMM_STATUS_ERROR 1 #define _HAL_PMM_SVMLE (SVMLE) #define _HAL_PMM_SVSLE (SVSLE) #define _HAL_PMM_SVSFP (SVSLFP) #define _HAL_PMM_SVMFP (SVMLFP) uint16_t SetVCore (uint8_t level); static uint16_t SetVCoreUp (uint8_t level); int main(void) { volatile unsigned int i; WDTCTL = WDTPW|WDTHOLD; // Stop WDT SetVCore(PMMCOREV_1); // Set VCore = 1.6V for 12MHz clock P1DIR |= BIT1; // P1.1 output P1DIR |= BIT0; // ACLK set out to pins P1SEL |= BIT0; P3DIR |= BIT4; // SMCLK set out to pins P3SEL |= BIT4; 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 24MHz operation UCSCTL2 = FLLD_1 + 374; // Set DCO Multiplier for 12MHz // (N + 1) * FLLRef = Fdco // (374 + 1) * 32768 = 12MHz // 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 6xx // UG for optimization. // 32 x 32 x 12 MHz / 32,768 Hz = 375000 = MCLK cycles for DCO to settle __delay_cycles(375000); // Loop until XT1,XT2 & DCO fault flag is cleared do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags }while (SFRIFG1&OFIFG); // Test oscillator fault flag while(1) { P1OUT ^= BIT1; // Toggle P1.1 __delay_cycles(600000); // Delay } } uint16_t SetVCore (uint8_t level) { uint16_t actlevel; uint16_t status = 0; level &= PMMCOREV_3; // Set Mask for Max. level actlevel = (PMMCTL0 & PMMCOREV_3); // Get actual VCore while (((level != actlevel) && (status == 0)) || (level < actlevel)) // step by step increase or decrease { if (level > actlevel) status = SetVCoreUp(++actlevel); } return status; } static uint16_t SetVCoreUp (uint8_t level) { uint16_t PMMRIE_backup,SVSMHCTL_backup; // Open PMM registers for write access PMMCTL0_H = 0xA5; // Disable dedicated Interrupts to prevent that needed flags will be cleared PMMRIE_backup = PMMRIE; PMMRIE &= ~(SVSMHDLYIE | SVSMLDLYIE | SVMLVLRIE | SVMHVLRIE | SVMHVLRPE); SVSMHCTL_backup = SVSMHCTL; PMMIFG &= ~(SVMHIFG | SVSMHDLYIFG); // Set SVM highside to new level and check if a VCore increase is possible SVSMHCTL = SVMHE | SVSHE | (SVSMHRRL0 * level); // Wait until SVM highside is settled while ((PMMIFG & SVSMHDLYIFG) == 0); // Check if a VCore increase is possible if ((PMMIFG & SVMHIFG) == SVMHIFG){ //-> Vcc is to low for a Vcore increase // recover the previous settings PMMIFG &= ~SVSMHDLYIFG; SVSMHCTL = SVSMHCTL_backup; // Wait until SVM highside is settled while ((PMMIFG & SVSMHDLYIFG) == 0); // Clear all Flags PMMIFG &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG | SVMLVLRIFG | SVMLIFG | SVSMLDLYIFG); // backup PMM-Interrupt-Register PMMRIE = PMMRIE_backup; // Lock PMM registers for write access PMMCTL0_H = 0x00; return PMM_STATUS_ERROR; // return: voltage not set } // Set also SVS highside to new level //-> Vcc is high enough for a Vcore increase SVSMHCTL |= (SVSHRVL0 * level); // Set SVM low side to new level SVSMLCTL = SVMLE | (SVSMLRRL0 * level); // Wait until SVM low side is settled while ((PMMIFG & SVSMLDLYIFG) == 0); // Clear already set flags PMMIFG &= ~(SVMLVLRIFG | SVMLIFG); // Set VCore to new level PMMCTL0_L = PMMCOREV0 * level; // Wait until new level reached if (PMMIFG & SVMLIFG) while ((PMMIFG & SVMLVLRIFG) == 0); // Set also SVS/SVM low side to new level PMMIFG &= ~SVSMLDLYIFG; SVSMLCTL |= SVSLE | (SVSLRVL0 * level); // wait for lowside delay flags while ((PMMIFG & SVSMLDLYIFG) == 0); // Disable SVS/SVM Low // Disable full-performance mode to save energy SVSMLCTL &= ~(_HAL_PMM_SVSLE + _HAL_PMM_SVMLE + _HAL_PMM_SVSFP + _HAL_PMM_SVMFP); SVSMHCTL &= ~(_HAL_PMM_SVSFP + _HAL_PMM_SVMFP); // Clear all Flags PMMIFG &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG | SVMLVLRIFG | SVMLIFG | SVSMLDLYIFG); // backup PMM-Interrupt-Register PMMRIE = PMMRIE_backup; // Lock PMM registers for write access PMMCTL0_H = 0x00; return PMM_STATUS_OK; // return: OK }
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
**Attention** This is a public forum