| Author |
Message |
Swys
Joined: 22 Jul 2008 Posts: 11
|
23 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
|
25 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

|
25 Jun 2009 13:35 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
bobcat1
Joined: 10 Jul 2002 Posts: 1100 Helped: 46
|
04 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 |
|
 |