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 initialization problems

Other Parts Discussed in Thread: MSP430F1611

NOTE: I posted this in the wrong forum, this is a repost of the same question.

 

I have been trying to get the code below to work for over a week now with no success. I am building a datalogger with a MSP430F1611 and I am using a MSP-FET430UIF to interface with the controller. I am new to embedded programming and taking an incremental approach to the coding. I first made an LED blink based off of the Timer A interrupt and now I am trying to get the SPI to talk to a 1GB SD card. I have read through the data sheets and online forums and I am still stuck. I run my code and use an oscilloscope to monitor the UCLK pin and see it rise to a steady 3.3V. I know I am new at this but I thought that there is supposed to be a steady pulse emanating from that pin! I wanted to see if it was transmitting and I wasn't using the oscilloscope correctly so I set the LISTEN bit and ran the program. I checked the receive register and there was nothing there.

 

I just want this darn thing to send out a steady clock signal and some kind of data stream, I appreciate any help I can get. 

 

 

#include <msp430f1611.h>

#include <mmc.h>

#include <stdio.h>

#include "fatlib.h"

#include "HALayer.h"

 

// Global Variables 

 

int Working = 0;

unsigned int buffer[512];

 

//Function declarations 

void cpu_init(void);

void spi_init(void);

 

void main(void)

{

  cpu_init();

  spi_init();

 

  while(1)

  {

 

    U1TXBUF = 0xaa; //Dummy value

//  for(int i=0;i<0xFF;i++);                           //Delay for Tx

 

  }

}

 

void cpu_init(void)

{

  WDTCTL = WDTPW + WDTHOLD;      // Stop watchdog timer

  P5SEL |= BIT1+BIT2+BIT3;                   // Set pins P5.1-3 to peripheral

  P5DIR |= BIT0;                                        //P5.0 output

  P5OUT &= ~BIT0;                                  //P5.0 Low

}

 

void spi_init(void)

{

  U1CTL |= SWRST; //disable state machine 

  U1CTL |= CHAR+SYNC+MM+LISTEN;            //8bit char, SPI,USART is master,Tx to Rx

  U1TCTL |= SSEL0+STC;                                     //UCLK=ACLK

  U1MCTL = 0x00;                                                   //No Modulation

  U1BR0 = 0x02;                                                     //Divide ACLK by 2

  U1BR1 = 0x00;

  ME2 |= USPIE1;                                                  //Enable SPI module

  U1CTL &= ~SWRST;                                        //Initialize state machine

}

  • David,

     

    Please take a look at the code examples for that device. They can be very helpfull when starting from scratch. There are a about 8 code examples that use the SPI configuration, ie. "fet140_spi0_03.c"

    http://www.ti.com/litv/zip/slac015n

     

    Try running them stand alone and then you can migrate them to your own code.

  • Thanks for the suggestion but I tried all of those on their own with no success. I didn't have anything connected to any pins when I tried it, thinking that if it worked a clock signal would be on the indicated pin. That never happened, I'm beginning to think there may be something wrong with the chip itself. I loaded someone else's program that worked before and that caused a clock signal on the right pin. However, whenever I attempted to write a new program using that same clock pin, the signal did not go away. I could not change it, I looked in memory and the right values were in the right registers to have the signal off, and yet, there it was. 

     

    Is there a way to clearly tell if a controller has gone bad? or if it is only a case of user error?

  • David Engineer said:
    I thought that there is supposed to be a steady pulse emanating from that pin!

    No. SPI works one clock pulse for each bit to transfer. No transfer, no clock. And transfers are always bi-directional (one clock pulse = one bit out and one bit in).

    So to get a clock, you'll have to send something. If you want to get something, you'll have to send something. Writing something to the TXBUF register starts sending and receiving and generates exactly 8 clock pulses after which a byte has been sent and a byte has been received (even if there is no slave at all: then 0xff has been received and the seinding went into nirvana)

  • I figured out a significant part of my problem, I did not have my compiler configured correctly. It was using a simulator instead of the JTAG, stupid me. I have the clock working just as Jens-Michael described and now I am trying to get the SD card to talk back. I suppose it is worth mentioning that my code has changed significantly since first posting. Thanks for the help.

**Attention** This is a public forum