SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By mmtronics
Hi everyone

I am using Olimex MSP430-449STK2 and ADE7878 development board. I am using IAR Embedded Workbench IDE.
I am trying to set-up SPI :( .
This is the code I have written below and I cannot find where I am making mistake :( .
Can someone help me with the code?

//*************************SPI INITAILIZE**************************
void spiInit(void) {

U0CTL = 0x17; // SPI, 8 bit data, no loopback, SPI mode, master, reset
U0TCTL = 0xE3; // SPI Mode 3, CKPH=0, CKPL=0, SMCLK, 3 pin mode, Tx empty
U0BR0 = 4; // smclk divider Maximum serial clock frequency = 2.5Mhz.
U0BR1 = 0; // 8MHz/4=2Mhz.
U0MCTL = 0; // not used, but should be 0
//IE1 &= ~0x80; // disable interrupts
IE1 = 0xC0;
ME1 |= 0x40; // enable spi module
//U0CTL &= ~1; // release reset
P3SEL = 0x00;
P3OUT = 0x00;
P3SEL |= 0xe; // P3 bits 1,2,3 used for spi
P3DIR |= 0xb; // P3 bits 0,1,3 used as output
P3DIR &= ~4; // P3 bit 2 input
P3OUT |= 0x01; // CS high

// Private module functions to manipulate SPI
void EnableSPI( void )
{ P3OUT &= ~0x01; // Set CS low

void DisableSPI( void )
{ P3OUT |= 0x01; // Set CS high

unsigned int ExecuteSPI( unsigned int nArg )
{ unsigned int data;

while ((IFG1 & UTXIFG0) == 0); // USART0 TX buffer ready?

IFG1 &= ~URXIFG0; // Clear Rx flag

// Exchange byte
TXBUF0 = nArg & 0xFF;
while ((IFG1 & UTXIFG0) == 0);
while ((IFG1 & URXIFG0) == 0);
data = RXBUF0;

return data;

unsigned int Read_Energy_Register(void)
unsigned int data;

data = ExecuteSPI(0x00);

return data;

//********************SPI turn OFF**********************************
void spiOff(void)
ME1 &= ~0x40; // disable spi module
By adigav
From what I read in the datasheet, u need to toggle the CS pin 3 times to set SPI. I dont see you setting the SPI, default it will be i2C mode. Also, each SPI communication should be proceeded by CS low and succeeded by CS high signals. Looks like you are having more than one SPI communication in between CS low and CS high.

Hope it helps!
By mmtronics
Hi adigav

"From what I read in the datasheet, u need to toggle the CS pin 3 times to set SPI."

Can you please give me the name and page number of the data sheet?

By mmtronics
adigav wrote:ADE 7878 data sheet. topic serial interface page 63
Hi adigav

I was looking at the wrong data sheet. The data sheet which came with on the CD was only 83 pages.
I have downloaded latest one from AD website and now SPI is working fine :) :D .

Thank you for helping me.
By adigav

I have a question. How did you interface the olimex with ADE7878 Development board. Did u break some circuitry and connect Olimex to ADE??

By mmtronics
Hi adigav

I have connected P11 on ADE7878 Development board to EXT(20 Pin Connector) on Olimex board.
By kanaknpk

I interfaced msp430f248 and ADE7878 in SPI communication. Its working fine in PSM1 mode, While switching PSM0 mode communication changes to I2C. How to change SPI communication in PSM0 mode, its not changing to SPI while toggling 3 times of chipselect pin.. Help me out how to change SPI?

thanks and regards
By adigav
Pls check your modes, PSM0 ( PM1 - 0 , PM0 - 1). If you have set this correctly then toggling 3 times SSB will set the SPI mode.
By kanaknpk

I got connected to SPI in PSM0 mode. I forget connect the Reset pin. Thank guys for the replies...

long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]