Rules | Recent posts | topic RSS | Search | Register  | Log in

ADE7753 and SPI


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> ADE7753 and SPI
Author Message
Swys



Joined: 22 Jul 2008
Posts: 11


Post23 Jun 2009 14:24   

ade7753 spi speed


Hi all,

I am trying to get the SPI communication going with the ADE7753. For the microcontroller I am using a PIC18F452.

I am posting my code. I am sure that the physical connections are correct. Can anyone please check my code and tell me where I am going wrong, please? I've tried for hours now and I think I am starting to go mad....

Thanks!

Code:
//Initialize the SPI
void init_spi()
{
   SSPEN = 0;            //Enable bit must be cleared to configure SPI
   
   TRISC = TRISC | 0b00010000;   //Setup the TRIS register
   
   CKP = 0;            //IDLE state for clock is a low level
   CKE = 0;            //Data transmitted on falling edge of clock
   SMP = 0;            //Input data sampled at the middle of data output time
   
   SSPCON1 = SSPCON1 | 0b00000010;   //Speed: Fosc/64
   
   SSPEN = 1;            //Enable the serial port
}


Code:
//Output one byte via SPI
//This function returns the data that may be present
//in the SSPBUF register. Otherwise returns 0
unsigned char spi_read_write(unsigned char data)
{
   unsigned char readData = 0;
   
   if (BF)
      readData = spi_read();
      
   SSPBUF = data;
   
   return readData;
}


Code:
//Receive one byte via SPI
unsigned char spi_read()
{
   while (!BF)
      continue;
   
   return SSPBUF;
}


Code:
//Test the SPI communication
void TestSPI()
{
   char command = 0x3F + 0x80;   //Read the die revision
   ADE7753RESET = 1;
   CS = 0;

   init_spi();
   
   spi_write(command);
   _delay(90);      //Delay for 90 clock cycles
   char result = 0;
   
   result = spi_read();
   
   CS = 1;
   
   putch(result);      //Output the receive value on the UART
}
Back to top
Swys



Joined: 22 Jul 2008
Posts: 11


Post25 Jun 2009 13:35   

ade7753 spi


O, forgot to mention...I am using the HI-TECH PIC18 C compiler.

I anyone able to help me with this?
Back to top
Google
AdSense
Google Adsense




Post25 Jun 2009 13:35   

Ads




Back to top
bobcat1



Joined: 10 Jul 2002
Posts: 1100
Helped: 46


Post04 Jul 2009 11:46   

Re: ADE7753 and SPI


HI

Do you have access to scop? it might help you debug your software hardware problem

All the best

Bobi
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> ADE7753 and SPI
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
ADE7753 (3)
ADE7753 S/W driver (3)
ADE7753 grounding (4)
help with ade7753 (18)
Help with ADE7753 (2)
Beginner in ADE7753 (8)
ADE7753 with PIC layout (3)
SPI and/or I2C and noise sensitivity (2)
PIC USB ADE7753 Ground Problems (1)
ADE7753 Problem with zero crossing (3)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS