MSP430F449 + ADE7878 SPI

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 :frowning: .

This is the code I have written below and I cannot find where I am making mistake :frowning: .

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

}

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!

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

ADE 7878 data sheet. topic serial interface page 63

adigav:
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 :slight_smile: :smiley: .

Thank you for helping me.

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.

Hi adigav

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

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

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.

Hi

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

regards

Kay

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.