Page 1 of 1

MSP430F449 + ADE7878 SPI

Posted: Thu Jun 03, 2010 2:23 am
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
//initialize
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;

EnableSPI();
ExecuteSPI(READ_ENERGY_REGISTER);
ExecuteSPI(0x00);
ExecuteSPI(0x00);
ExecuteSPI(0x01);
data = ExecuteSPI(0x00);
DisableSPI();

return data;
}

//********************SPI turn OFF**********************************
void spiOff(void)
{
ME1 &= ~0x40; // disable spi module
}

Re: MSP430F449 + ADE7878 SPI

Posted: Mon Jun 07, 2010 1:16 pm
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!

Re: MSP430F449 + ADE7878 SPI

Posted: Tue Jun 08, 2010 2:13 am
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?

Thanks

Re: MSP430F449 + ADE7878 SPI

Posted: Tue Jun 08, 2010 4:47 pm
by adigav
ADE 7878 data sheet. topic serial interface page 63

Re: MSP430F449 + ADE7878 SPI

Posted: Wed Jun 09, 2010 4:49 am
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.

Re: MSP430F449 + ADE7878 SPI

Posted: Mon Jun 14, 2010 10:28 am
by adigav
Hi,

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

Thanks.

Re: MSP430F449 + ADE7878 SPI

Posted: Tue Jun 29, 2010 5:44 am
by mmtronics
Hi adigav

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

Re: MSP430F449 + ADE7878 SPI

Posted: Fri Oct 08, 2010 9:08 am
by kanaknpk
Hi

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
Kay

Re: MSP430F449 + ADE7878 SPI

Posted: Fri Oct 08, 2010 10:35 am
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.

Re: MSP430F449 + ADE7878 SPI

Posted: Sat Oct 09, 2010 9:05 am
by kanaknpk
Hi

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

regards
Kay

Re: MSP430F449 + ADE7878 SPI

Posted: Mon Oct 03, 2011 6:28 pm
by kuinida00
Hi everyone.
Do you have the CD of the ADE7878 development board? I am a student and trying to learn the ADE7878 development.
If convenient, please sent to my email: longmarchmm184@hotmail.com. Thanks a lot.