Hi hmani,
I like to know how make the communication between PIC18f2550 and ADE7758. On page 17 of the datasheet has a basic circuit of protection. I use the pins: 2, 3, 4, 11, 12, 13, 18, 19, 20, 21, 22, 23 and 24 to start communication SPI. This is correct?
My code:
function in file comunication.h:
unsigned char packetSetRegisterRead(unsigned char address){
//Configurando pacote
unsigned char packet = 0x00;
packet = address;
packet &= 0b01111111;
//Enviando o pacote
return WriteSPI(packet);
}
#include <comunication.h>
#define slave1 PORTAbits.RA5
void main()
//My information
unsigned char infoEnableComunication = COMPMODE; //MODE;
//Reception date
unsigned char dado = 0x00;
//Set the slave
TRISAbits.TRISA5 = 0; //Pin Slave - output
//Set of the sck, sdi and sdo
TRISBbits.TRISB1 = 0; //SCK
TRISBbits.TRISB0 = 1; //SDI
TRISCbits.TRISC7 = 0; //SDO
TRISAbits.TRISA2 = 1; //IRQ
//Set SPI
OpenSPI(SPI_FOSC_16, MODE_00, SMPEND); //Open SPI
//disable the slave
slave1 = 1;
while(1){
//Slave enable
slave1 = 0;
packetSetRegisterRead(infoEnableComunication);
slave1 = 1;
slave1 = 0;
Delay10KTCYx(50);
if (DataRdySPI()) dado = ReadSPI();
slave1 = 1;
}
}
What is the problem in my code?
Regards
petrucior