MSP430F449 + ADE7878 SPI

Discussions on how to get your MSP JTAG programmer up and running.

Moderator: phalanx

Post Reply
mmtronics
Posts: 4
Joined: Thu Jun 03, 2010 1:50 am

MSP430F449 + ADE7878 SPI

Post by mmtronics » Thu Jun 03, 2010 2:23 am

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
}

adigav
Posts: 4
Joined: Mon Jun 07, 2010 1:10 pm

Re: MSP430F449 + ADE7878 SPI

Post by adigav » Mon Jun 07, 2010 1:16 pm

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!

mmtronics
Posts: 4
Joined: Thu Jun 03, 2010 1:50 am

Re: MSP430F449 + ADE7878 SPI

Post by mmtronics » Tue Jun 08, 2010 2:13 am

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

adigav
Posts: 4
Joined: Mon Jun 07, 2010 1:10 pm

Re: MSP430F449 + ADE7878 SPI

Post by adigav » Tue Jun 08, 2010 4:47 pm

ADE 7878 data sheet. topic serial interface page 63

mmtronics
Posts: 4
Joined: Thu Jun 03, 2010 1:50 am

Re: MSP430F449 + ADE7878 SPI

Post by mmtronics » Wed Jun 09, 2010 4:49 am

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.

adigav
Posts: 4
Joined: Mon Jun 07, 2010 1:10 pm

Re: MSP430F449 + ADE7878 SPI

Post by adigav » Mon Jun 14, 2010 10:28 am

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.

mmtronics
Posts: 4
Joined: Thu Jun 03, 2010 1:50 am

Re: MSP430F449 + ADE7878 SPI

Post by mmtronics » Tue Jun 29, 2010 5:44 am

Hi adigav

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

kanaknpk
Posts: 2
Joined: Wed Oct 06, 2010 7:12 am

Re: MSP430F449 + ADE7878 SPI

Post by kanaknpk » Fri Oct 08, 2010 9:08 am

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

adigav
Posts: 4
Joined: Mon Jun 07, 2010 1:10 pm

Re: MSP430F449 + ADE7878 SPI

Post by adigav » Fri Oct 08, 2010 10:35 am

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.

kanaknpk
Posts: 2
Joined: Wed Oct 06, 2010 7:12 am

Re: MSP430F449 + ADE7878 SPI

Post by kanaknpk » Sat Oct 09, 2010 9:05 am

Hi

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

regards
Kay

kuinida00
Posts: 1
Joined: Mon Oct 03, 2011 5:43 am

Re: MSP430F449 + ADE7878 SPI

Post by kuinida00 » Mon Oct 03, 2011 6:28 pm

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.

Post Reply