Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SPI Programming from a MSP430 -> LTC1960

Status
Not open for further replies.

Aichibo

Newbie level 2
Joined
Aug 4, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
UK
Activity points
1,303
Hey, I've come on a bit since I was initially trying to get my programming skills up to scratch to even make an LED flash.

My next task is to try and get the MSP430 chip I've been working with to "talk" to an LTC1960 via SPI. I think I've set it up correctly.. can anyone see any problems with this?

Code:
#include "msp430x22x4.h"

void spiInit(void);

void main(void)
{
	volatile int i,j;
	spiInit();
	
	while (1)
	{	
		UCB0TXBUF = 0x20; // Dummy Write
		for(i=0;i<10000;i++); // Wait a while
		{
			for(j=0;j<10;j++);
		}
	}
}

void spiInit(void)
{
	UCB0CTL0 = 0x17; // SPI, 8 bit data, no loopback, SPI mode, master, reset
	UCB0CTL1 = 0xa1; // CKPH=1, CKPL=0, SMCLK, 4 pin mode, Tx empty
	
	UCB0BR0 = 2; //SMCLK divider
	UCB0BR1 = 0;
	
	IE1 &= ~0x80; // disable SPI interrupts
	IE1 &= ~0x40;
	
	P3SEL |= 0x39; // P3 bits 0,3,4,5 as spi
	P3DIR |= 0x19; // P3 bits 0,3,4 as output
	P3DIR |= 0x20; // P3 bit 5 as input	
	
	UCB0CTL0 &= ~1; // release reset
	
	UCB0TXBUF = 0x00; // Dummy Write
}

Thanks :)
 

Hello!

OK, what do you want to say?
You think it is setup correctly, but you don't say if it works.
I suppose it doesn't otherwise you wouldn't post, but what is the problem?
The best way to get replies would be to explain the problem symptoms accurately?
Does it loop forever and you don't get the data you sent? Does it block? … etc…

Now some comments about the way you setup your SPI.
You write:
UCB0CTL0 = 0x17;

That's fine, but doing so you have a higher error probability. Just suppose that you have
set bit 4 instead of bit 5. If you write 0x17, I cannot debug because I don't know by heard
which bit of UCB0CTL0 does what.

Instead, if you write for instance:
Code:
UCB0CTL0 = UCMST   |  // CPU is master
            UCSYNC |  //Synchronous transfer
            UCCKPL |  //Reverse polarity
            UCMSB;    //Send MSB first

then:
- You are sure that the right bit is set at the right place;
- It's easy to debug; (if for instance the polarity is wrong, then comment out the proper line, and so on).
- It's easy to debug by another person (If I want to check, then I have no other solution than opening
the MCU docs and check the registers;

Dora.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top